# Conflicts:
#	doc/软件开发项目的个人自评报告-基于热成像技术的无人机自动跟踪项目.xlsx
master
laptoy 5 months ago
commit 03dce11193

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 MiB

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

@ -0,0 +1 @@
# CMake generation timestamp file for this directory.

@ -0,0 +1,11 @@
# CMake generation dependency list for this directory.
E:/openpose/openpose_prosperity/examples/tutorial_api_python/01_body_from_image.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/02_whole_body_from_image.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/04_keypoints_from_images.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/05_keypoints_from_images_multi_gpu.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/06_face_from_image.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/07_hand_from_image.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/08_heatmaps_from_image.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/09_keypoints_from_heatmaps.py
E:/openpose/openpose_prosperity/examples/tutorial_api_python/CMakeLists.txt
E:/openpose/openpose_prosperity/examples/tutorial_api_python/openpose_python.py

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6927D627-3432-3371-AC7A-318D1A465B17}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
<Platform>x64</Platform>
<ProjectName>INSTALL</ProjectName>
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Utility</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Utility</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PostBuildEvent>
<UseUtf8Encoding>Always</UseUtf8Encoding>
<Message></Message>
<Command>setlocal
"C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=$(Configuration) -P cmake_install.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PostBuildEvent>
<UseUtf8Encoding>Always</UseUtf8Encoding>
<Message></Message>
<Command>setlocal
"C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=$(Configuration) -P cmake_install.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<CustomBuild Include="E:\openpose\openpose_prosperity\build\CMakeFiles\52e4f4e96e416b306a37548352e90ea2\INSTALL_force.rule">
<BuildInParallel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</BuildInParallel>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> </Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">setlocal
cd .
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">E:\openpose\openpose_prosperity\build\examples\tutorial_api_python\CMakeFiles\INSTALL_force</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkObjects>
<VerifyInputsAndOutputsExist Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</VerifyInputsAndOutputsExist>
<BuildInParallel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</BuildInParallel>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> </Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">setlocal
cd .
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">E:\openpose\openpose_prosperity\build\examples\tutorial_api_python\CMakeFiles\INSTALL_force</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkObjects>
<VerifyInputsAndOutputsExist Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</VerifyInputsAndOutputsExist>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="E:\openpose\openpose_prosperity\build\3rdparty\pybind11\ALL_BUILD.vcxproj">
<Project>{B248B77E-735C-311D-A166-2EFEAABC52A9}</Project>
<Name>ALL_BUILD</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<CustomBuild Include="E:\openpose\openpose_prosperity\build\CMakeFiles\52e4f4e96e416b306a37548352e90ea2\INSTALL_force.rule">
<Filter>CMake Rules</Filter>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<Filter Include="CMake Rules">
<UniqueIdentifier>{7BC68FB9-1045-3D7A-A2DB-568B5960D265}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

@ -0,0 +1,147 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse# 导入argparse模块用于解析命令行参数
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
# 创建一个ArgumentParser对象用于处理命令行参数
parser = argparse.ArgumentParser()
# 添加一个命令行参数 --image_path它有一个默认值用于指定要处理的图像文件路径
# 这个参数接受所有标准的图像格式如jpg, png, bmp等
parser.add_argument("--image_path",
default="../../../examples/media/COCO_val2014_000000000192.jpg",
help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
# 解析命令行参数,并获取已知的参数和未知参数(如果有的话)
# parse_known_args()方法返回两个值一个是已知参数的Namespace对象另一个是未知参数的列表
args = parser.parse_known_args()
# 创建一个字典params用于存储自定义参数
# 这些参数通常用于配置OpenPose的行为但不在默认的命令行参数中
params = dict()
# 设置一个自定义参数model_folder指定OpenPose模型文件的存储路径
params["model_folder"] = "../../../models/"
# 遍历args[1](未知参数的列表),以处理可能通过命令行传递的额外自定义参数
# 注意args[0]是Namespace对象包含已知参数args[1]是未知参数的列表
for i in range(0, len(args[1])):
curr_item = args[1][i] # 当前项
# 检查是否还有下一个项并设置next_item的值
# 如果当前项是列表中的最后一个项,则假设下一个项为"1"(这里可能是一个简化的处理方式)
if i != len(args[1]) - 1:
next_item = args[1][i + 1]
else:
next_item = "1"
# 检查当前项和下一个项是否都以"--"开头,这通常意味着它们都是命令行参数(但这里逻辑可能不完全准确)
# 如果两个都是参数,则忽略它们,因为这里的逻辑可能不适用于处理真正的命令行参数
# 注意:这里的逻辑可能是一个错误或简化的处理方式,因为通常不会这样检查参数
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-', '') # 移除参数名中的'-'并作为字典的键
if key not in params: # 如果该键不在params字典中则添加它并赋值为"1"(这可能不是预期的行为)
params[key] = "1"
# 如果当前项以"--"开头但下一个项不是,则假设当前项是一个参数,而下一个项是该参数的值
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-', '') # 同样移除'-'
if key not in params: # 如果该键不在params字典中则添加它并将next_item作为值
params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
# 初始化OpenPose的WrapperPython对象
# WrapperPython是OpenPose提供的Python接口的主要类用于封装OpenPose的功能
opWrapper = op.WrapperPython()
# 使用自定义参数配置OpenPose
# params是一个字典包含了OpenPose运行所需的配置参数
# 这些参数可以影响OpenPose的性能、输出等
opWrapper.configure(params)
# 启动OpenPose
# 在配置完成后需要调用start方法来初始化OpenPose的内部结构
opWrapper.start()
# 处理图像
# 创建一个Datum对象Datum是OpenPose用于存储输入和输出数据的类
datum = op.Datum()
# 使用OpenCV读取图像
#args是一个元组且args[0]是Namespace对象则应该是args[0].image_path
imageToProcess = cv2.imread(args[0].image_path)
# 将读取的图像设置为Datum对象的输入数据
datum.cvInputData = imageToProcess
# 调用emplaceAndPop方法处理图像
# 这个方法将Datum对象包含输入图像放入OpenPose的处理队列中并等待处理结果
# 处理完成后结果会被放入Datum对象的输出字段中
# 注意这里传递了一个包含datum的VectorDatum对象因为emplaceAndPop方法期望接收一个VectorDatum作为参数
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
# 显示处理结果
# 打印出图像中的人体关键点信息
# poseKeypoints是一个包含关键点信息的列表或数组
print("Body keypoints: \n" + str(datum.poseKeypoints))
# 使用OpenCV显示处理后的图像
# cvOutputData是Datum对象中包含的处理后图像数据
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
# 等待用户按键后关闭窗口
cv2.waitKey(0)
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,158 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# 创建一个ArgumentParser对象用于添加和解析命令行参数
parser = argparse.ArgumentParser()
# 向ArgumentParser对象添加一个命令行参数 --image_path
# default: 设置参数的默认值,这里是一个图片的路径
# help: 当用户在命令行中使用 --help 时,显示的帮助信息
parser.add_argument("--image_path",
default="../../../examples/media/COCO_val2014_000000000241.jpg",
help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
# 解析命令行参数parse_known_args()方法返回一个包含两个元素的元组
# 第一个元素是一个Namespace对象包含了解析后的参数
# 第二个元素是一个列表,包含所有未识别的参数(在这个例子中,由于我们只定义了一个参数,这个列表应该是空的)
# 注意通常我们会使用parse_args()而不是parse_known_args(),除非需要特别处理未识别的参数
args = parser.parse_known_args()
# 创建一个字典,用于存储自定义参数
# 这些参数可能会用于配置OpenPose或其他图像处理库
params = dict()
# 向params字典中添加一个键值对指定模型文件夹的路径
# 这个路径应该包含OpenPose的模型文件
params["model_folder"] = "../../../models/"
# 向params字典中添加一个键值对指示是否处理人脸关键点
# True表示启用人脸关键点检测
params["face"] = True
# 向params字典中添加一个键值对指示是否处理手部关键点
# True表示启用手部关键点检测
params["hand"] = True
# 遍历args[1](未知参数的列表),以处理可能通过命令行传递的额外自定义参数
# 注意args[0]是Namespace对象包含已知参数args[1]是未知参数的列表
for i in range(0, len(args[1])):
curr_item = args[1][i] # 当前项
# 检查是否还有下一个项并设置next_item的值
# 如果当前项是列表中的最后一个项,则假设下一个项为"1"(这里可能是一个简化的处理方式)
if i != len(args[1]) - 1:
next_item = args[1][i + 1]
else:
next_item = "1"
# 检查当前项和下一个项是否都以"--"开头,这通常意味着它们都是命令行参数(但这里逻辑可能不完全准确)
# 如果两个都是参数,则忽略它们,因为这里的逻辑可能不适用于处理真正的命令行参数
# 注意:这里的逻辑可能是一个错误或简化的处理方式,因为通常不会这样检查参数
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-', '') # 移除参数名中的'-'并作为字典的键
if key not in params: # 如果该键不在params字典中则添加它并赋值为"1"(这可能不是预期的行为)
params[key] = "1"
# 如果当前项以"--"开头但下一个项不是,则假设当前项是一个参数,而下一个项是该参数的值
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-', '') # 同样移除'-'
if key not in params: # 如果该键不在params字典中则添加它并将next_item作为值
params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# 初始化OpenPose的WrapperPython对象
opWrapper = op.WrapperPython()
# 使用自定义参数配置OpenPose
# params是一个字典包含了OpenPose运行所需的配置参数
# 这些参数可能包括模型路径、是否检测面部、手部等
opWrapper.configure(params)
# 启动OpenPose
# 在配置完成后需要调用start方法来初始化OpenPose的内部结构
opWrapper.start()
# 处理图像
# 创建一个Datum对象Datum是OpenPose用于存储输入和输出数据的类
datum = op.Datum()
imageToProcess = cv2.imread(args[0].image_path)
# 将读取的图像设置为Datum对象的输入数据
datum.cvInputData = imageToProcess
# 调用emplaceAndPop方法处理图像
# 这个方法将Datum对象包含输入图像放入OpenPose的处理队列中并等待处理结果
# 处理完成后结果会被放入Datum对象的输出字段中
# 注意这里传递了一个包含datum的VectorDatum对象因为emplaceAndPop方法期望接收一个VectorDatum作为参数
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
# 显示处理结果
# 打印出图像中的人体、面部以及左右手的关键点信息
print("Body keypoints: \n" + str(datum.poseKeypoints))
print("Face keypoints: \n" + str(datum.faceKeypoints))
print("Left hand keypoints: \n" + str(datum.handKeypoints[0]))
print("Right hand keypoints: \n" + str(datum.handKeypoints[1]))
# 使用OpenCV显示处理后的图像
# 注意datum.cvOutputData可能包含原始图像和处理结果的叠加具体取决于OpenPose的配置
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
# 等待用户按键后关闭窗口
cv2.waitKey(0)
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,34 @@
# Install script for directory: E:/openpose/openpose_prosperity/examples/tutorial_api_python
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "C:/Program Files/OpenPose")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Release")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE")
endif()

@ -0,0 +1,135 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
import time
try:
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
parser = argparse.ArgumentParser()
parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000241.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
args = parser.parse_known_args()
# 自定义参数(更多参数在 include/openpose/flags.hpp 文件)
params = dict()
# 设置存放 OpenPose 模型的文件夹路径
params["model_folder"] = "../../../models/"
# 启用面部关键点检测
params["face"] = True
# 选择使用的面部检测器模型(这里的数字 2 表示选择了特定的模型)
params["face_detector"] = 2
# 禁用身体关键点检测0 表示不检测身体关键点)
params["body"] = 0
# Add others in path?
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
# 初始化 OpenPose 的 Python 包装器
opWrapper = op.WrapperPython()
# 配置 OpenPose 使用的参数
opWrapper.configure(params)
# 启动 OpenPose
opWrapper.start()
# 读取要处理的图像
imageToProcess = cv2.imread(args[0].image_path)
# 定义面部矩形的位置信息
faceRectangles = [
op.Rectangle(330.119385, 277.532715, 48.717274, 48.717274),
op.Rectangle(24.036991, 267.918793, 65.175171, 65.175171),
op.Rectangle(151.803436, 32.477852, 108.295761, 108.295761),
]
# 创建一个新的 Datum 对象,用于存储处理后的结果
datum = op.Datum()
# 设置输入图像数据
datum.cvInputData = imageToProcess
# 设置面部矩形位置信息
datum.faceRectangles = faceRectangles
# 处理图像并显示结果
# 将输入数据放入处理队列并从中获取处理后的数据
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
# 输出面部关键点的信息
print("Face keypoints: \n" + str(datum.faceKeypoints))
# 在窗口中显示处理后的图像
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
# 等待用户按下任意键后关闭窗口
cv2.waitKey(0)
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,148 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
import time
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
# 创建一个ArgumentParser对象用于处理命令行参数
parser = argparse.ArgumentParser()
# 添加一个命令行参数 --image_path它有一个默认值用于指定要处理的图像文件路径
# 这个参数接受所有标准的图像格式如jpg, png, bmp等
parser.add_argument("--image_path",
default="../../../examples/media/COCO_val2014_000000000192.jpg",
help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
# 解析命令行参数,并获取已知的参数和未知参数(如果有的话)
# parse_known_args()方法返回两个值一个是已知参数的Namespace对象另一个是未知参数的列表
args = parser.parse_known_args()
# 创建一个字典params用于存储自定义参数
# 这些参数通常用于配置OpenPose的行为但不在默认的命令行参数中
params = dict()
# 设置一个自定义参数model_folder指定OpenPose模型文件的存储路径
params["model_folder"] = "../../../models/"
# 启用手部关键点检测
params["hand"] = True
# 设置手部检测器的类型为2可能是特定于手部检测的算法或模型
params["hand_detector"] = 2
# 禁用身体关键点检测
params["body"] = 0
# Add others in path?
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
# 创建 OpenPose 的 Python 包装器实例
opWrapper = op.WrapperPython()
# 配置 OpenPose 实例的参数
opWrapper.configure(params)
# 启动 OpenPose 实例
opWrapper.start()
# 读取要处理的图像和手部矩形位置
imageToProcess = cv2.imread(args[0].image_path)
handRectangles = [
# 第0个人的左/右手
[
op.Rectangle(320.035889, 377.675049, 69.300949, 69.300949), # 左手矩形
op.Rectangle(0., 0., 0., 0.), # 右手矩形(未定义,可以为空)
],
# 第1个人的左/右手
[
op.Rectangle(80.155792, 407.673492, 80.812706, 80.812706), # 左手矩形
op.Rectangle(46.449715, 404.559753, 98.898178, 98.898178), # 右手矩形
],
# 第2个人的左/右手
[
op.Rectangle(185.692673, 303.112244, 157.587555, 157.587555), # 左手矩形
op.Rectangle(88.984360, 268.866547, 117.818230, 117.818230), # 右手矩形
]
]
# 创建一个新的 datum 对象
datum = op.Datum()
# 设置 datum 对象的输入图像数据和手部矩形位置
datum.cvInputData = imageToProcess
datum.handRectangles = handRectangles
# 处理图像并获取结果
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
# 打印左手和右手的关键点信息
print("Left hand keypoints: \n" + str(datum.handKeypoints[0]))
print("Right hand keypoints: \n" + str(datum.handKeypoints[1]))
# 显示处理后的图像
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
cv2.waitKey(0) # 等待按键响应,然后关闭窗口
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,123 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
# 创建参数解析器
parser = argparse.ArgumentParser()
# 添加命令行参数选项
parser.add_argument("--image_path",
default="../../../examples/media/COCO_val2014_000000000192.jpg",
help="处理一张图片。支持所有标准格式jpg、png、bmp等")
args = parser.parse_known_args()
# 自定义参数设置(更多参数详见 include/openpose/flags.hpp
params = dict()
params["model_folder"] = "../../../models/" # 模型文件夹路径
params["heatmaps_add_parts"] = True # 是否生成人体部位热图
params["heatmaps_add_bkg"] = True # 是否生成背景热图
params["heatmaps_add_PAFs"] = True # 是否生成关键点连接热图PAFs
params["heatmaps_scale"] = 2 # 热图的缩放比例
# Add others in path?
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
# 创建 OpenPose 的 Python 包装器实例
opWrapper = op.WrapperPython()
opWrapper.configure(params) # 配置 OpenPose 实例的参数
opWrapper.start() # 启动 OpenPose 实例
# 处理图像
datum = op.Datum() # 创建一个 datum 对象来存储处理结果
imageToProcess = cv2.imread(args[0].image_path) # 读取要处理的图像
datum.cvInputData = imageToProcess # 设置输入图像数据
opWrapper.emplaceAndPop(op.VectorDatum([datum])) # 对图像进行处理并获取结果
# 处理输出
outputImageF = (datum.inputNetData[0].copy())[0, :, :, :] + 0.5 # 处理输出图像数据
outputImageF = cv2.merge([outputImageF[0, :, :], outputImageF[1, :, :], outputImageF[2, :, :]]) # 合并通道
outputImageF = (outputImageF * 255.).astype(dtype='uint8') # 转换为 uint8 类型
heatmaps = datum.poseHeatMaps.copy() # 复制姿势热图数据
heatmaps = (heatmaps).astype(dtype='uint8') # 转换为 uint8 类型
# 显示图像
counter = 0
while 1:
num_maps = heatmaps.shape[0] # 获取热图数量
heatmap = heatmaps[counter, :, :].copy() # 获取当前计数器对应的热图
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) # 将热图应用颜色映射
combined = cv2.addWeighted(outputImageF, 0.5, heatmap, 0.5, 0) # 合并原始图像和热图
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", combined) # 显示合成图像
key = cv2.waitKey(-1) # 等待按键事件
if key == 27: # 如果按下 ESC 键,则退出循环
break
counter += 1
counter = counter % num_maps # 循环更新计数器,确保在热图数量内循环显示
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,118 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
import numpy as np
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
# 创建参数解析器
parser = argparse.ArgumentParser()
parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000294.jpg",
help="处理一张图片支持所有标准格式jpg、png、bmp 等)")
args = parser.parse_known_args()
# 加载图片
imageToProcess = cv2.imread(args[0].image_path)
def get_sample_heatmaps():
# 全局设置参数,如果有新的 OpenPose 对象,需要取消在这里设置的变量。参见 *
params = dict()
params["model_folder"] = "../../../models/"
params["heatmaps_add_parts"] = True # 添加部位热图
params["heatmaps_add_bkg"] = True # 添加背景热图
params["heatmaps_add_PAFs"] = True # 添加关键点之间的关联热图
params["heatmaps_scale"] = 3 # 热图缩放因子
params["upsampling_ratio"] = 1 # 上采样比例
params["body"] = 1 # 选择身体关键点
# 启动 OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# 处理图片并获取热图
datum = op.Datum()
imageToProcess = cv2.imread(args[0].image_path)
datum.cvInputData = imageToProcess
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
poseHeatMaps = datum.poseHeatMaps.copy()
opWrapper.stop()
return poseHeatMaps
# 获取热图
poseHeatMaps = get_sample_heatmaps()
# 启动 OpenPose
params = dict()
params["model_folder"] = "../../../models/"
params["body"] = 2 # 禁用 OP Network
params["upsampling_ratio"] = 0 # * 取消设置此变量
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# 传递热图并运行 OpenPose
datum = op.Datum()
datum.cvInputData = imageToProcess
datum.poseNetOutput = poseHeatMaps
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
# 显示图片
print("Body keypoints: \n" + str(datum.poseKeypoints))
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
cv2.waitKey(0)
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,109 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
import time
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
parser = argparse.ArgumentParser()
parser.add_argument("--image_dir", default="../../../examples/media/", help="Process a directory of images. Read all standard formats (jpg, png, bmp, etc.).")
parser.add_argument("--no_display", default=False, help="Enable to disable the visual display.")
args = parser.parse_known_args()
# Custom Params (refer to include/openpose/flags.hpp for more parameters)
params = dict()
params["model_folder"] = "../../../models/"
# Add others in path?
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# 读取目录中的图片
imagePaths = op.get_images_on_directory(args[0].image_dir)
start = time.time()
# 处理并显示图片
for imagePath in imagePaths:
datum = op.Datum()
imageToProcess = cv2.imread(imagePath)
datum.cvInputData = imageToProcess
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
print("Body keypoints: \n" + str(datum.poseKeypoints))
if not args[0].no_display:
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
key = cv2.waitKey(15)
if key == 27: break
end = time.time()
print("OpenPose demo successfully finished. Total time: " + str(end - start) + " seconds")
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,107 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
try:
# Import Openpose (Windows/Ubuntu/OSX)
# 获取当前脚本文件的目录路径
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# 检查操作系统类型
# Windows Import
# 对于Windows系统
if platform == "win32":
# 修改这些变量以指向正确的文件夹如Release/x64等
# 使用 os.path.join 来避免路径分隔符的问题
openpose_path = os.path.join(dir_path, '../../python/openpose/Release')
sys.path.append(openpose_path)
#sys.path.append(dir_path + '/../../python/openpose/Release');
#os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
# 设置环境变量PATH以便可以在命令行中调用OpenPose的可执行文件
# 在Python脚本中通常不需要这样做这样可以在脚本中调用OpenPose的可执行文件
# 使用 os.pathsep 来确保路径分隔符的正确性
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(dir_path,'../../x64/Release') \
+ os.pathsep + os.path.join(dir_path, '../../bin')
# 导入OpenPose的Python接口
import pyopenpose as op
else:
# 对于Linux或MacOS系统
# 修改这些变量以指向正确的文件夹如Release/x64等
# 这里假设OpenPose的Python库位于相对于脚本的固定路径下
sys.path.append('../../python')
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
# 如果运行了 `make install`对于Ubuntu默认路径是 `/usr/local/python`则也可以从那里访问OpenPose/python模块
# 注意通常不需要这样做除非OpenPose的Python库确实被安装到了非标准路径
# 并且下面的代码行已经被注释掉了因为它可能会覆盖掉其他重要的Python库路径
# sys.path.append('/usr/local/python')
# 从openpose模块导入pyopenpose
from openpose import pyopenpose as op
except ImportError as e:
# 如果在尝试导入pyopenpose时发生错误则打印错误消息并重新抛出异常
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
# 打印原始异常信息
print(e)
# 重新抛出异常,以便调用者可以处理它
raise e
# Flags
# 创建参数解析器对象
parser = argparse.ArgumentParser()
# 添加命令行参数 --image_path设置默认值为指定路径的图像文件
parser.add_argument("--image_path",
default="../../../examples/media/COCO_val2014_000000000192.jpg",
help="处理一张图片。支持所有标准格式jpg、png、bmp 等)。")
# 解析命令行参数,并返回一个包含参数对象和额外参数的元组
args = parser.parse_known_args()
# 自定义参数(更多参数请参考 include/openpose/flags.hpp
params = dict()
# 设置模型文件夹的路径
params["model_folder"] = "../../../models/"
# 遍历额外的命令行参数(通常是以 -- 开头的参数)
for i in range(0, len(args[1])):
curr_item = args[1][i] # 当前参数
if i != len(args[1]) - 1:
next_item = args[1][i + 1] # 下一个参数
else:
next_item = "1" # 如果没有下一个参数,默认为 "1"
# 如果当前参数和下一个参数都以 -- 开头
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-', '') # 去掉参数中的 "-" 符号,作为键名
if key not in params:
params[key] = "1" # 将参数加入到 params 字典中,值设为 "1"(默认值)
# 如果当前参数以 -- 开头,但下一个参数不是以 -- 开头(即下一个参数是当前参数的值)
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-', '') # 去掉参数中的 "-" 符号,作为键名
if key not in params:
params[key] = next_item # 将下一个参数作为当前参数的值加入到 params 字典中
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
# 创建 OpenPose 的 Python 封装器,指定线程管理模式为同步模式
opWrapper = op.WrapperPython(op.ThreadManagerMode.Synchronous)
# 使用提供的参数配置 OpenPose 封装器
opWrapper.configure(params)
# 执行 OpenPose 运行,开始处理图像或视频
opWrapper.execute()
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,60 @@
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
try:
# Import Openpose (Windows/Ubuntu/OSX)
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# Windows Import
if platform == "win32":
# Change these variables to point to the correct folder (Release/x64 etc.)
sys.path.append(dir_path + '/../../build/python/openpose/Release');
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../build/bin;'
import pyopenpose as op
else:
# Change these variables to point to the correct folder (Release/x64 etc.)
sys.path.append('../../python');
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
from openpose import pyopenpose as op
except ImportError as e:
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
raise e
# Flags
parser = argparse.ArgumentParser()
parser.add_argument("--image_path", default="../../examples/media/COCO_val2014_000000000192.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
args = parser.parse_known_args()
# Custom Params (refer to include/openpose/flags.hpp for more parameters)
params = dict()
params["model_folder"] = "../../models/"
# Add others in path?
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
opWrapper = op.WrapperPython(op.ThreadManagerMode.Synchronous)
opWrapper.configure(params)
opWrapper.execute()
except Exception as e:
print(e)
sys.exit(-1)

@ -0,0 +1,68 @@
import cv2
import pyopenpose as op
# RTSP地址
rtsp_url = "rtsp://192.168.1.115"
# 打开RTSP流
cap = cv2.VideoCapture(rtsp_url)
# 检查摄像头是否成功打开
if not cap.isOpened():
print("无法打开摄像头")
exit()
# 创建视频写入对象,用于保存视频
out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (640, 480))
# OpenPose 参数
params = {
"model_folder": "../../../models/", # 替换为您的 OpenPose 模型文件夹路径
"hand": False, # 是否检测手部关键点
"face": False, # 是否检测面部关键点
"display": 0, # 显示窗口的级别0为不显示
}
# 初始化 OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# 读取并显示视频流
while True:
ret, frame = cap.read()
if not ret:
print("无法读取视频流")
break
# 执行姿态检测
datum = op.Datum()
datum.cvInputData = frame
opWrapper.emplaceAndPop([datum])
# 获取姿态检测结果
pose_keypoints = datum.poseKeypoints
# 在帧上绘制姿态关键点
if pose_keypoints is not None:
for person in pose_keypoints:
for point in person:
if point[2] > 0.1: # 确保置信度足够高
cv2.circle(frame, (int(point[0]), int(point[1])), 4, (0, 255, 255), thickness=-1, lineType=cv2.FILLED)
# 显示视频流
cv2.imshow('RTSP Stream', frame)
# 写入视频帧到输出文件
out.write(frame)
# 按下'q'键退出循环
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 释放资源
cap.release()
out.release()
cv2.destroyAllWindows()

@ -0,0 +1,41 @@
import cv2
# RTSP地址
rtsp_url = "rtsp://192.168.1.135"
# 打开RTSP流
cap = cv2.VideoCapture(rtsp_url)
# 检查摄像头是否成功打开
if not cap.isOpened():
print("无法打开摄像头")
exit()
# 创建视频写入对象,用于保存视频
out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (640, 480))
# 读取并显示视频流
while True:
ret, frame = cap.read()
if not ret:
print("无法读取视频流")
break
# 在这里你可以对帧进行处理,例如进行对象检测、图像处理等
# 显示视频流
cv2.imshow('RTSP Stream', frame)
# 写入视频帧到输出文件
out.write(frame)
# 按下'q'键退出循环
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 释放资源
cap.release()
out.release()
cv2.destroyAllWindows()

@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 22:19:59 2024
@author: lenovo
"""
import cv2
import pyopenpose as op
# RTSP地址
rtsp_url = "rtsp://192.168.1.135"
# 打开RTSP流
cap = cv2.VideoCapture(rtsp_url)
# 检查摄像头是否成功打开
if not cap.isOpened():
print("无法打开摄像头")
exit()
# 创建视频写入对象,用于保存视频
out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (640, 480))
# OpenPose 参数
params = {
"model_folder": "../../../models/", # 替换为您的 OpenPose 模型文件夹路径
"hand": False, # 是否检测手部关键点
"face": False, # 是否检测面部关键点
"display": 0, # 显示窗口的级别0为不显示
}
# 初始化 OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# 读取并显示视频流
while True:
ret, frame = cap.read()
if not ret:
print("无法读取视频流")
break
# 执行姿态检测
datum = op.Datum()
datum.cvInputData = frame
opWrapper.emplaceAndPop([datum])
# 获取姿态检测结果
pose_keypoints = datum.poseKeypoints
# 在帧上绘制姿态关键点
if pose_keypoints is not None:
for person in pose_keypoints:
for point in person:
if point[2] > 0.1: # 确保置信度足够高
cv2.circle(frame, (int(point[0]), int(point[1])), 4, (0, 255, 255), thickness=-1, lineType=cv2.FILLED)
# 显示视频流
cv2.imshow('RTSP Stream', frame)
# 写入视频帧到输出文件
out.write(frame)
# 按下'q'键退出循环
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 释放资源
cap.release()
out.release()
cv2.destroyAllWindows()

@ -0,0 +1,120 @@
import tkinter as tk
from tkinter import ttk
def save_settings():
# Placeholder for saving settings logic
print("Settings saved.")
# Create main window
root = tk.Tk()
root.title("设备连接与配置")
# Frame for serial settings
serial_frame = ttk.LabelFrame(root, text="串口和波特率")
serial_frame.grid(row=0, column=0, padx=10, pady=5, sticky=tk.W)
serial_port_label = ttk.Label(serial_frame, text="串口:")
serial_port_label.grid(row=0, column=0, padx=5, pady=2, sticky=tk.W)
serial_port_combo = ttk.Combobox(serial_frame, width=8, values=["COM1", "COM2", "COM3"])
serial_port_combo.grid(row=0, column=1, padx=5, pady=2)
serial_port_combo.set("COM1") # Set default value
baudrate_label = ttk.Label(serial_frame, text="波特率:")
baudrate_label.grid(row=1, column=0, padx=5, pady=2, sticky=tk.W)
baudrate_combo = ttk.Combobox(serial_frame, width=8, values=["9600", "19200", "115200"])
baudrate_combo.grid(row=1, column=1, padx=5, pady=2)
baudrate_combo.set("115200") # Set default value
# Frame for TCP settings
tcp_frame = ttk.LabelFrame(root, text="TCP配置")
tcp_frame.grid(row=1, column=0, padx=10, pady=5, sticky=tk.W)
tcp_ip_label = ttk.Label(tcp_frame, text="TCP 远端 IP:")
tcp_ip_label.grid(row=0, column=0, padx=5, pady=2, sticky=tk.W)
tcp_ip_combo = ttk.Combobox(tcp_frame, width=15, values=["192.168.1.100", "192.168.1.101", "192.168.1.102"])
tcp_ip_combo.grid(row=0, column=1, padx=5, pady=2)
tcp_ip_combo.set("192.168.1.100") # Set default value
tcp_port_label = ttk.Label(tcp_frame, text="端口:")
tcp_port_label.grid(row=1, column=0, padx=5, pady=2, sticky=tk.W)
tcp_port_entry = ttk.Entry(tcp_frame, width=8)
tcp_port_entry.grid(row=1, column=1, padx=5, pady=2)
tcp_port_entry.insert(0, "2000")
# Frame for UDP settings
udp_frame = ttk.LabelFrame(root, text="UDP配置")
udp_frame.grid(row=2, column=0, padx=10, pady=5, sticky=tk.W)
udp_remote_ip_label = ttk.Label(udp_frame, text="UDP 远端 IP:")
udp_remote_ip_label.grid(row=0, column=0, padx=5, pady=2, sticky=tk.W)
udp_remote_ip_combo = ttk.Combobox(udp_frame, width=15, values=["192.168.2.100", "192.168.2.101", "192.168.2.102"])
udp_remote_ip_combo.grid(row=0, column=1, padx=5, pady=2)
udp_remote_ip_combo.set("192.168.2.100") # Set default value
udp_remote_port_label = ttk.Label(udp_frame, text="远端端口:")
udp_remote_port_label.grid(row=1, column=0, padx=5, pady=2, sticky=tk.W)
udp_remote_port_entry = ttk.Entry(udp_frame, width=8)
udp_remote_port_entry.grid(row=1, column=1, padx=5, pady=2)
udp_remote_port_entry.insert(0, "14551")
udp_local_ip_label = ttk.Label(udp_frame, text="UDP 本地 IP:")
udp_local_ip_label.grid(row=2, column=0, padx=5, pady=2, sticky=tk.W)
udp_local_ip_combo = ttk.Combobox(udp_frame, width=15, values=["192.168.2.101", "192.168.2.102", "192.168.2.103"])
udp_local_ip_combo.grid(row=2, column=1, padx=5, pady=2)
udp_local_ip_combo.set("192.168.2.101") # Set default value
udp_local_port_label = ttk.Label(udp_frame, text="本地端口:")
udp_local_port_label.grid(row=3, column=0, padx=5, pady=2, sticky=tk.W)
udp_local_port_entry = ttk.Entry(udp_frame, width=8)
udp_local_port_entry.grid(row=3, column=1, padx=5, pady=2)
udp_local_port_entry.insert(0, "14550")
# Frame for video settings
video_frame = ttk.LabelFrame(root, text="视频功能")
video_frame.grid(row=3, column=0, padx=10, pady=5, sticky=tk.W)
# Network video options
network_video_var = tk.IntVar()
network_video_label = ttk.Label(video_frame, text="网络视频地址:")
network_video_label.grid(row=0, column=1, padx=5, pady=2, sticky=tk.W)
network_video_radio1 = ttk.Radiobutton(video_frame, variable=network_video_var, value=1)#text="选项1",
network_video_radio1.grid(row=0, column=0, padx=5, pady=2, sticky=tk.W )
network_video_entry = ttk.Entry(video_frame, width=20)
network_video_entry.grid(row=0, column=4, padx=5, pady=2)
network_video_combo = ttk.Combobox(tcp_frame, width=15, values=["192.168.1.100", "192.168.1.101", "192.168.1.102"])
network_video_combo.grid(row=0, column=5, padx=5, pady=2)
network_video_combo.set("192.168.2.101") # Set default value
# 禁用网络视频输入框,除非选择了网络视频选项
def update_entry_state():
network_video_entry.config(state='normal' if network_video_var.get() == 1 else 'disabled')
# network_video_var.trace_add('write', update_entry_state)
# update_entry_state() # 初始化时调用一次以设置正确的状态
# USB device options
#usb_device_var = tk.IntVar()
usb_device_label = ttk.Label(video_frame, text="USB 设备:")
usb_device_label.grid(row=1, column=1, padx=5, pady=2, sticky=tk.W)
usb_device_radio1 = ttk.Radiobutton(video_frame, variable=network_video_var, value=2)#text="Camera1",
usb_device_radio1.grid(row=1, column=0, padx=5, pady=2, sticky=tk.W)
usb_device_entry = ttk.Entry(video_frame, width=20)
usb_device_entry.grid(row=1, column=4, padx=5, pady=2)
usb_device_combo = ttk.Combobox(tcp_frame, width=15, values=["192.168.1.100", "192.168.1.101", "192.168.1.102"])
usb_device_combo.grid(row=1, column=5, padx=5, pady=2)
usb_device_combo.set("192.168.2.101") # Set default value
# Save settings button
save_button = ttk.Button(root, text="保存设置", command=save_settings)
save_button.grid(row=4, column=0, pady=10)
save_button = ttk.Button(root, text="连接设备", command=save_settings)
save_button.grid(row=5, column=0, pady=10)
root.mainloop()

@ -0,0 +1,96 @@
import subprocess
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
class MainWindow(tk.Tk):
def __init__(self):
super().__init__()
self.title("带菜单栏、按钮和自适应图片的窗口示例")
# 设置窗口初始大小
self.geometry("800x600") # 宽度800像素高度600像素
# 创建菜单栏
self.menu_bar = tk.Menu(self)
file_menu = tk.Menu(self.menu_bar, tearoff=0)
file_menu.add_command(label="Command 1", command=self.menu_command_1)
file_menu.add_command(label="Command 2", command=self.menu_command_2)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=self.quit)
self.menu_bar.add_cascade(label="File", menu=file_menu)
edit_menu = tk.Menu(self.menu_bar, tearoff=0)
edit_menu.add_command(label="Command 3", command=self.menu_command_3)
self.menu_bar.add_cascade(label="Edit", menu=edit_menu)
self.config(menu=self.menu_bar)
# 创建左侧帧
self.left_frame = tk.Frame(self, width=200, bg='light grey')
self.left_frame.pack(side=tk.LEFT, fill=tk.Y)
# 左侧按钮
self.button1 = ttk.Button(self.left_frame, text="地图定位", command=self.map_command_1)
self.button1.pack(pady=10)
self.button4 = ttk.Button(self.left_frame, text="连接无人机", command=self.connect_command_1)
self.button4.pack(pady=10)
self.button2 = ttk.Button(self.left_frame, text="路线规划", command=lambda: print("Button 2 clicked"))
self.button2.pack(pady=10)
self.button3 = ttk.Button(self.left_frame, text="人物识别", command=self.show_image)
self.button3.pack(pady=10)
self.button5 = ttk.Button(self.left_frame, text="跟踪信息", command=self.show_image)
self.button5.pack(pady=10)
# 创建中间区域的Frame
self.center_frame = tk.Frame(self, bg='white')
self.center_frame.pack(expand=True, fill=tk.BOTH)
# 显示图片的Label
self.image_label = tk.Label(self.center_frame, bg='white')
self.image_label.place(relx=0.5, rely=0.5, anchor=tk.CENTER) # 居中放置
# 加载并显示图片
self.load_and_display_image("img2.png")
# 监听窗口大小变化事件
self.bind("<Configure>", self.on_window_resize)
def menu_command_1(self):
print("Menu Command 1")
def menu_command_2(self):
print("Menu Command 2")
def menu_command_3(self):
print("Menu Command 3")
def map_command_1(self):
subprocess.run(["python", "map.py"])
def connect_command_1(self):
subprocess.run(["python", "connect.py"])
def show_image(self):
self.load_and_display_image("img2.png")
def load_and_display_image(self, image_path):
# 加载图片并调整大小以适应窗口
img = Image.open(image_path)
width, height = self.winfo_width(), self.winfo_height() # 获取当前窗口大小
img = img.resize((width, height), Image.ANTIALIAS)
self.photo = ImageTk.PhotoImage(img)
self.image_label.config(image=self.photo)
def on_window_resize(self, event):
# 窗口大小变化时重新调整图片大小
self.load_and_display_image("img2.png")
if __name__ == "__main__":
app = MainWindow()
app.mainloop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

@ -0,0 +1,218 @@
import tkinter as tk # 使用Tkinter前需要先导入
import tkinter.messagebox
import pickle
import subprocess
from tkinter import font
from PIL import Image, ImageTk
def resize_image(event):
# 计算新的图片大小,保持原始比例
new_width = event.width
scale_factor = new_width / image_original.width
new_height = int(image_original.height * scale_factor)
# 使用 PIL 缩放图片
resized_image = image_original.resize((new_width, new_height), Image.ANTIALIAS)
# 创建新的 PhotoImage 对象
photo = ImageTk.PhotoImage(resized_image)
# 更新 Canvas 上的图片
canvas.itemconfig(image_id, image=photo)
# 确保图片居中
canvas.coords(image_id, (event.width // 2 - new_width // 2, event.height // 2 - new_height // 2))
#实例化object建立窗口window
window = tk.Tk()
#给窗口的可视化起名字
window.title('Wellcome to Hongwei Website')
# 设定窗口的大小(长 * 宽)
window.geometry('500x535') # 这里的乘是小x
#加载 wellcome image
# 加载图片并获取原始尺寸
image_original = Image.open('img1.png')
image_width, image_height = image_original.size
# 创建一个 Canvas
canvas = tk.Canvas(window, width=500, height=335, bg='black')
canvas.pack(fill='both', expand=True) # 让 Canvas 填充整个窗口并随窗口大小变化
# 创建一个图片项目并保存其 ID
image_id = canvas.create_image(0, 0, anchor='nw', image=None) # 初始位置设为左上角
image_file = tk.PhotoImage(file='img1.png')
image = canvas.create_image(250, 0, anchor='n', image=image_file)
# canvas.pack(side='top')
# 绑定窗口的 <Configure> 事件到 resize_image 函数
window.bind('<Configure>', resize_image)
tk.Label(window, text='Wellcome', font=('Arial', 16)).pack()
# 加载并显示图片(注意:这里只加载图片到变量,不直接显示在 Canvas 上)
photo = ImageTk.PhotoImage(image_original)
# 确保 Tkinter 的图片对象不会被垃圾回收
photo_ref = [] # 创建一个列表来引用图片对象
# 首次显示图片
photo = ImageTk.PhotoImage(image_original)
photo_ref.append(photo) # 添加到列表中防止被回收
canvas.itemconfig(image_id, image=photo)
canvas.coords(image_id, (canvas.winfo_width() // 2 - image_width // 2, canvas.winfo_height() // 2 - image_height // 2))
# 用户信息
# tk.Label(window, text='User name:', font=('Arial', 14)).place(x=10, y=175)
# tk.Label(window, text='Password:', font=('Arial', 14)).place(x=10, y=215)
# 用户信息标签
label_usr_name = tk.Label(window, text='User name:', font=('Arial', 13))
label_usr_name.place(x=10, y=175)
label_usr_pwd = tk.Label(window, text='Password: ', font=('Arial', 13))
label_usr_pwd.place(x=10, y=215)
# 用户登录输入框entry
# 用户名
var_usr_name = tk.StringVar()
var_usr_name.set('example@python.com')
entry_usr_name = tk.Entry(window, textvariable=var_usr_name, font=('Arial', 14))
# entry_usr_name.place(x=120, y=175)
entry_width = 200
entry_usr_name.place(x=label_usr_name.winfo_x() + label_usr_name.winfo_width() + 120, y=175, width=entry_width)
# 用户密码
var_usr_pwd = tk.StringVar()
entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, font=('Arial', 14), show='*')
# entry_usr_pwd.place(x=120, y=215)
entry_usr_pwd.place(x=label_usr_pwd.winfo_x() + label_usr_pwd.winfo_width() + 120, y=215, width=entry_width)
# 输入框在垂直方向上居中,可以调整 rowconfigure
# 假设你的窗口只有两个行,并且你希望它们平分空间
window.rowconfigure(0, weight=1)
window.rowconfigure(1, weight=1)
# 定义用户登录功能
def usr_login():
# 这两行代码就是获取用户输入的usr_name和usr_pwd
usr_name = var_usr_name.get()
usr_pwd = var_usr_pwd.get()
# 这里设置异常捕获,当我们第一次访问用户信息文件时是不存在的,所以这里设置异常捕获。
# 中间的两行就是我们的匹配,即程序将输入的信息和文件中的信息匹配。
try:
with open('usrs_info.pickle', 'rb') as usr_file:
usrs_info = pickle.load(usr_file)
except FileNotFoundError:
# 这里就是我们在没有读取到`usr_file`的时候,程序会创建一个`usr_file`这个文件,并将管理员
# 的用户和密码写入,即用户名为`admin`密码为`admin`。
with open('usrs_info.pickle', 'wb') as usr_file:
usrs_info = {'admin': 'admin'}
pickle.dump(usrs_info, usr_file)
usr_file.close() # 必须先关闭否则pickle.load()会出现EOFError: Ran out of input
# 如果用户名和密码与文件中的匹配成功则会登录成功并跳出弹窗how are you? 加上你的用户名。
if usr_name in usrs_info:
if usr_pwd == usrs_info[usr_name]:
tkinter.messagebox.showinfo(title='Welcome', message='How are you? ' + usr_name)
window.destroy()
subprocess.run(["python", "home.py"])
# 如果用户名匹配成功,而密码输入错误,则会弹出'Error, your password is wrong, try again.'
else:
tkinter.messagebox.showerror(message='Error, your password is wrong, try again.')
else: # 如果发现用户名不存在
is_sign_up = tkinter.messagebox.askyesno('Welcome ', 'You have not sign up yet. Sign up now?')
# 提示需不需要注册新用户
if is_sign_up:
usr_sign_up()
# 第9步定义用户注册功能
def usr_sign_up():
def sign_to_Hongwei_Website():
# 以下三行就是获取我们注册时所输入的信息
np = new_pwd.get()
npf = new_pwd_confirm.get()
nn = new_name.get()
# 这里是打开我们记录数据的文件,将注册信息读出
# with open('usrs_info.pickle', 'rb') as usr_file:
# exist_usr_info = pickle.load(usr_file)
# 尝试加载已存在的用户信息,如果文件不存在或为空,则使用空字典
try:
with open('usrs_info.pickle', 'rb') as usr_file:
exist_usr_info = pickle.load(usr_file)
except (FileNotFoundError, EOFError):
exist_usr_info = {} # 如果文件不存在或为空,则创建一个空字典
# 这里就是判断如果两次密码输入不一致则提示Error, Password and confirm password must be the same!
if np != npf:
tkinter.messagebox.showerror('Error', 'Password and confirm password must be the same!')
# 如果用户名已经在我们的数据文件中则提示Error, The user has already signed up!
elif nn in exist_usr_info:
tkinter.messagebox.showerror('Error', 'The user has already signed up!')
# 最后如果输入无以上错误则将注册输入的信息记录到文件当中并提示注册成功Welcome,You have successfully signed up!,然后销毁窗口。
else:
exist_usr_info[nn] = np
with open('usrs_info.pickle', 'wb') as usr_file:
pickle.dump(exist_usr_info, usr_file)
tkinter.messagebox.showinfo('Welcome', 'You have successfully signed up!')
# 然后销毁窗口。
window_sign_up.destroy()
# 定义长在窗口上的窗口
window_sign_up = tk.Toplevel(window)
window_sign_up.geometry('300x200')
window_sign_up.title('Sign up window')
new_name = tk.StringVar() # 将输入的注册名赋值给变量
new_name.set('example@python.com') # 将最初显示定为'example@python.com'
tk.Label(window_sign_up, text='User name: ').place(x=10, y=10) # 将`User name:`放置在坐标10,10
entry_new_name = tk.Entry(window_sign_up, textvariable=new_name) # 创建一个注册名的`entry`,变量为`new_name`
entry_new_name.place(x=130, y=10) # `entry`放置在坐标150,10.
new_pwd = tk.StringVar()
tk.Label(window_sign_up, text='Password: ').place(x=10, y=50)
entry_usr_pwd = tk.Entry(window_sign_up, textvariable=new_pwd, show='*')
entry_usr_pwd.place(x=130, y=50)
new_pwd_confirm = tk.StringVar()
tk.Label(window_sign_up, text='Confirm password: ').place(x=10, y=90)
entry_usr_pwd_confirm = tk.Entry(window_sign_up, textvariable=new_pwd_confirm, show='*')
entry_usr_pwd_confirm.place(x=130, y=90)
# 下面的 sign_to_Hongwei_Website
btn_comfirm_sign_up = tk.Button(window_sign_up, text='Sign up', command=sign_to_Hongwei_Website)
btn_comfirm_sign_up.place(x=180, y=120)
# btn_login = tk.Button(window, text='登录', command=usr_login)
# btn_login.place(x=120, y=340)
# btn_sign_up = tk.Button(window, text='注册', command=usr_sign_up)
# btn_sign_up.place(x=200, y=340)
# 创建一个字体对象,用于设置按钮字体和大小
button_font = font.Font(family='Helvetica', size=14, weight='bold')
# 创建登录按钮
btn_login = tk.Button(window, text='登录', command=usr_login, font=button_font, bg='lightblue', fg='white',
borderwidth=2, relief='raised')
btn_login.place(x=140, y=340, width=80, height=30) # 这里设置了按钮的宽度和高度(以字符为单位)
# 创建注册按钮
btn_sign_up = tk.Button(window, text='注册', command=usr_sign_up, font=button_font, bg='lightgreen', fg='white',
borderwidth=2, relief='raised')
btn_sign_up.place(x=250, y=340, width=80, height=30) # 同样设置了按钮的宽度和高度(以字符为单位)
# ... 其他代码 ...
window.mainloop()
# 第10步主窗口循环显示
window.mainloop()

@ -0,0 +1,11 @@
import webbrowser
# 假设你的HTML文件位于当前工作目录的"maps"文件夹下
file_path = 'showpoint.html' # 替换为你的HTML文件路径
# 使用默认浏览器打开HTML文件
#webbrowser.open_new_tab(file_path) # 或者使用 webbrowser.open(file_path) 来打开新窗口
# 在新窗口中打开而不是新标签页,可以这样做:
webbrowser.get('windows-default').open_new(file_path) # Windows
# webbrowser.get('firefox').open_new(file_path) # 指定浏览器如Firefox
Loading…
Cancel
Save