openpose从安装到实战全攻略!(win11)
补充
人体姿态估计简介
人体姿态估计数据集
链接: COCO Keypoints challenge
链接: MPII Human Pose Dataset
链接: VGG Pose Dataset
链接: CMU Panoptic Dataset(本案例所用数据集)
前言
本文无openpose介绍。仅有安装到实例化讲解。(2022年8月25日)。文中所有脚本 或 cmake 下载慢的皆可根据连接自行网络下载(作者本人电信验证)速度可大幅提升。
操作环境:
win11
openpose 1.7.0
cmake: 3.23.3
VS2019
python 3.7
一、基本配置
1、github上下载openpose后,解压到自己的目录下,建议不要解压到含有中文路径的地方。
https://github.com/CMU-Perceptual-Computing-Lab/openpose/tree/v1.7.0
2、从github下载pybind11(v2.10.0),并放置在该 3rdparty 目录下。
https://github.com/pybind/pybind11
3、首先下载所需文件,打开到openpose-master\3rdparty\windows 下,可以看到五个bat文件
将所有下载的压缩包解压到此目录下
此时所需文件基本下载完成。
二、CMAKE配置
1、打开CMAKE-gui
2、如果后续想要使用python运行并修改程序,请务必进行以下操作
点击 Add Entry
选择到对应环境的python.exe下就ok了。
3、然后进行configure一次
会出现一片红
选择BUILD_PYTHON (非必须,如果你要用python就选)
选择以下五个模型(必选)
debug直到configure done
然后点击generate,出现generate done即可
三、VS运行
进入工程文件,打开build,应该会有.sln文件,双击打开VS 2019
选择Release 模式,点击生成,生成解决方案。
全部生成后。右键运行 01_body_from_image_default
四、python运行
然后我们进行python调试
1、打开\openpose-master\build\examples\tutorial_api_python
可以选择pycharm or cmd运行,本文选择pycharm。
2、pycharm 设置python解释器环境,也就是 cmake-gui 中指定的 PYTHON_EXCUTABLE 对应的 python解释器环境。
3、直接运行任意01-09的一个py文件。
五、修改python代码读取自己的摄像头
# 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 + '/../../python/openpose/Release');
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../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
params = dict()
params["model_folder"] = "../../../models/"
params["hand"] = False
params["number_people_max"] = 1
params["disable_blending"] = True # for black background
# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# Process Image
datum = op.Datum()
cap = cv2.VideoCapture(0) #输入视频
fps = cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
framecount = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print('Total frames in this video: ' + str(framecount))
#videoWriter = cv2.VideoWriter("op720_2.avi", cv2.VideoWriter_fourcc('D', 'I', 'V', 'X'), fps, size)
c = 0
while cap.isOpened():
hasFrame, frame = cap.read()
if hasFrame:
img_resize = cv2.resize(frame, (640, 360))
datum.cvInputData = img_resize
opWrapper.emplaceAndPop(op.VectorDatum([datum]))
opframe = datum.cvOutputData
cv2.imshow("main", opframe)
c = c+1
#videoWriter.write(opframe)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
except Exception as e:
print(e)
sys.exit(-1)