OpenPose 安装,踩坑,使用记录(获取关键点)

根据下面三个链接的信息是可以清楚的成功安装CPU版本的openpose的。GPU的我没尝试目前,不过网上也有很多教程。

环境:

  1. windows 11 64bit;
  2. Visual Studio 2019 Community
  3. PyCharm 2021.3 Community

安装链接:

windows11下编译openpose并通过pyCharm调用

Windows10 OpenPose 环境搭建(CPU)

Windows+CPU+Openpose调通笔记

问题:

cmake配置出现No CMAKE_CXX_COMPILER could be found问题解决

当时也是出了这个问题,然后看了很多帖子,比如Visual Studio的安装路径不能有中文,然后还可能是Cmake版本问题,还有就是清除cmake缓存。
最终解决:
Visual Studio安装的时候需要装上C++选项,然后我应该是SDK版本问题,我刚开始没管,以为系统有,后面我修改了一下SDK,就是在intsaller里面多装了一个SDK11,后面就好了。反正多分析一下,多想一下,就很好解决了。

通过openpose得到关键点:

后面通过openpose,设置参数等得到人体关键点,然后需要注意的是参数的设置。
首先我们需要搭建我们所需要的模型,这样可以方便使用以及调用。
链接:

openpose环境搭建(详细教程CPU/GPU)windows 10+python 3.7+CUDA 11.6+VS2022

除了这一个外,上面三个链接里面也有相关内容。

搭建好之后,就可以根据代码进行测试了。

#-*- codeing = utf-8 -*-
#@Time : 2022/12/12 11:49
#@Author : Tom
#@File : openposetestdemo.py
#@Software : PyCharm

import os
import sys
import cv2
from sys import platform
import argparse

# get absolute path
dir_path = os.path.dirname(os.path.realpath(__file__))

# get bin directory
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/bin;'
import pyopenpose as op

print(op)
print("成功引入pyopenpose")

parser = argparse.ArgumentParser()
# 测试图片的路径要改一下,自己修改
parser.add_argument("--image_path",
default="image/000003_0.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()

# 修改参数
 # 修改分辨率,可以降低对显存的占用 (16的倍数)
params["net_resolution"] = "256x192"
params["write_json"] = "jsonPose"
# get 18 points
params["model_pose"] = "COCO"

# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()

# Process Image
datum = op.Datum()
# get image input ndarray
imageToProcess = cv2.imread(args[0].image_path)
datum.cvInputData = imageToProcess
opWrapper.emplaceAndPop(op.VectorDatum([datum]))


keypoints = datum.poseKeypoints

# print(keypoints.shape[1])
# Display Image
print("Total %d posekeypoints" % (keypoints.shape[1]))
print(" Body keypoints: \n" + str(datum.poseKeypoints))
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
cv2.waitKey(0)


这里面的代码最好是看一下,看一下之后再对图片路径以及参数进行设置,就能得到我们想要的。我需要的是得到18个关键点,模型设置为COCO即可。

关于参数不懂得可以自行搜索一下:

OpenPose 使用介紹

Github 项目 - OpenPose 参数说明

openpose关键点标记

目前的使用也就是到这了。

猜你喜欢

转载自blog.csdn.net/aaatomaaa/article/details/128270567
今日推荐