Openpose environment construction (detailed tutorial CPU/GPU) windows 10+python 3.7+CUDA 11.6+VS2022

【Play with OpenPose】Compilation

OpenPose Human Pose Recognition is an open source library developed by Carnegie Mellon University (CMU) based on convolutional neural network and supervised learning with Caffe as the framework. It can realize pose estimation such as human body movements, facial expressions, and finger movements. Suitable for single player and multiplayer, with excellent robustness. It is the world's first real-time multi-person 2D pose estimation application based on deep learning.
Compiled OpenPose project: uploaded for everyone to use (including CPU version and GPU version) (C++ interface and Python interface)

1. Development environment

1. System environment

operating system CPU GPU
windows 10 Intel® Core™ i5-8300H GeForce GTX 1050 Ti

2. Software environment

python CUDA CUDNN Visual Studio Cmake
3.7 v11.6 8.4 2022 community 3.24

2. Download and install

2.1 CUDA (for high-performance computing) and CUDNN (for deep neural network computing support)

① Official tutorial:

CUDA:https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html
CUDNN:https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installwindows

② CUDA installation
CUDA toolkit Download:https://developer.nvidia.com/cuda-toolkit-archive

Right-click on the desktop to open the NVIDIA control panel, click Help-System Information-Components , and check the CUDA version supported by your graphics card:
insert image description here
Download the corresponding version from the CUDA website: Download
insert image description here
the installation package:
insert image description here
**Install CUDA: **Keep the default path

insert image description hereinsert image description here
insert image description here
insert image description here
For the installation path of CUDA, just keep the default, and silently install it on the C drive (ensure that the C drive has enough space to prevent the later compilation from finding the CUDA path).

After the installation is complete:
Check whether the environment variable exists:
insert image description here
insert image description here
If the system variable is not automatically configured, we need to configure it manually. The path is specified according to whether it has been modified before.

**Finally:** After configuring the environment variables, let's check whether CUDA is installed successfully.

  • open cmd
  • enter
nvcc -V 

or

nvcc --version

insert image description here
It shows that cuda_11.6 has been downloaded successfully!

③ CUDNN installation
Official website download: https://developer.nvidia.com/rdp/cudnn-archive

CUDNN needs to be installed corresponding to the CUDA version.
insert image description here
insert image description here
After downloading and decompressing all the files:
insert image description here
CUDA and CUDNN are installed successfully! ! !

2.2 Download Cmake

Download the version for:
link: https://cmake.org/download/
insert image description here
and unzip it! Just see Cmake-gui .

2.3 Download 0penPose source code

Method 1: Open the browser and click to download
the official link of openpose: https://github.com/CMU-Perceptual-Computing-Lab/openpose (requires scientific exploration to download quickly)

Method 2: git command download

git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose.git

Download the required model:
1. Run getModels.bat in .../openpose-master/models/ and use Thunder to download the face model: http://posefs1.perception.cs.cmu.edu/OpenPose/models/face/pose_iter_116000 .caffemodel hand model: http://posefs1.perception.cs.cmu.edu/OpenPose/models/hand/pose_iter_102000.caffemodel pose/body_25 model: http://posefs1.perception.cs.cmu.edu/OpenPose/models /pose/body_25/pose_iter_584000.caffemodel pose/coco model: http://posefs1.perception.cs.cmu.edu/OpenPose/models/pose/coco/pose_iter_440000.caffemodel pose/mpi model: http://posefs1.perception .cs.cmu.edu/OpenPose/models/pose/mpi/pose_iter_160000.caffemodel 2. Run …/openpose-master/3rdparty/ windows






①getCaffe.bat | ②getCaffe3rdparty.bat | ③getFreeglut.bat | ④getOpenCV.bat | ⑤getSpinnaker.bat
(slow speed,share with Baidu Netdisk - replace 3rdparty/windows)

2.4 Download caffe-openpose source code

Method 1: Link to download
caffe Link: https://github.com/CMU-Perceptual-Computing-Lab/caffe
Method 2: git command to download

git clone https://github.com/CMU-Perceptual-Computing-Lab/caffe.git

Unzip the file and place it in .../openpose-master/3rdparty/ to cover caffe

2.5 Download pybind11 source code

Method 1: Link to download
caffe Link: https://github.com/pybind/pybind11
Method 2: git command to download

git clone https://github.com/pybind/pybind11.git

Unzip the file and place it in .../openpose-master/3rdparty/ to cover pybind11

3. Compile OpenPose (the above steps are completed - start compiling)

1. Create two folders under the openpose-master directory, namely build_GPU and build_CPU .
2. Open cmake-gui in cmake-3.24.0-windows-x86_64/bin

3.1 Compile GPU

Modify the path first, and then add the Python interface to modify the python program.
insert image description here

insert image description here
Then, click Configure
insert image description here
to add the VS version
insert image description here
and then set it
insert image description here
insert image description here
. Since the GPU version is used GPU_MODE = CUDA ,
insert image description here
then click Configure and then click Generate
insert image description here
. After the generation is complete, click Open Project to open the project in VS2022. In Release and x64 modes, generate the solution and wait for completion. .
insert image description here
When the following insert image description here
OpenPose python package appears, the compilation is complete. In the build_GPU/python/openpose/Release directory, the pyd file.

3.2 Compile the CPU

Modify the path first, and then add the Python interface to modify the python program.
insert image description here
insert image description here
Then, click Configure
insert image description here

After adding the VS version , set it to cancel USE_CUDNN due to the use of CPU version GPU_MODE = CPU_ONLY
insert image description here

insert image description here
insert image description here


insert image description here

Then click Configure and then click Generate.
insert image description here
After the generation is complete, click Open Project to open the project in VS2022. In Release and x64 modes, generate a solution and wait for completion.
insert image description here
The following appearsinsert image description here

At this point, the python package of OpenPose is compiled, and the pyd file is in the build_CPU/python/openpose/Release directory.

3.3 demo test (GPU version and CPU version are the same)

After the above steps are completed, the C++ examples can be run. All the C++ examples are here. If you need to use any example, just right-click it and set it as the startup project , and then run it .
insert image description here
operation result:
insert image description here

4. Establish OpenPoseDemo project

4.1 Create a project first, create a bin directory and a models directory, put the dependent related files in the bin directory, and put the model files in the models.

insert image description here

4.2 Copy openpose.dll in the build_GPU(build_CPU)/x64/Release directory to the bin directory of the project

insert image description here

4.3 Copy all the files in the build_GPU(build_CPU)/bin directory to the bin directory of the project

insert image description here

After copying:
insert image description here

4.4 Copy the pyopenpose.cp37-win_amd64.pyd file in the build_GPU(build_CPU)/python/openpose/Release directory to the root directory of the project

insert image description here
After copying:
insert image description here

4.5 Copy all the files in the openpose/models directory to the project's /models directory

insert image description here
After copying:
insert image description here

4.6 The main file is ready, use python to test whether it is available

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

dir_path = os.path.dirname(os.path.realpath(__file__))

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="examples/COCO_val2014_000000000623.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"] = "368x256" 

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

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

# Display Image
print("Body keypoints: \n" + str(datum.poseKeypoints))
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)
cv2.waitKey(0)

It runs successfully when the following phenomena occur:
insert image description here

5. Frequently asked questions

5.1 Check failed: error == cudaSuccess (2 vs. 0) out of memory

Due to the error caused by insufficient GPU memory, modify the net_resolution parameter 368x368 (a multiple of 16)
or --number_people_max to reduce the number of trackers

C++ interface , plus --net_resolution 160x160. for example:

OpenPoseDemo.exe --video video.avi --net_resolution 160x160

Python interface , also similar:

python demo.py --net_resolution 160x160

The specific parameter value of net_resolution can be modified according to your own needs. The smaller the resolution, the larger the number of frames transmitted per second (fps), but the smaller the accuracy rate. On the contrary, the larger it is. But it must be a multiple of 16. Otherwise, this error message will appear: Error: Net input resolution must be multiples of 16.

5.2 Prompts may appear during the cmake process

pybind11 does not contain a CMakeLists.txt file

pybind11 is missing in the openpose source code file, and pybind11 is a tool for basic type conversion between c++ and python.
Re-download pybind11 and put it in. Unzip the file and place it in .../openpose-master/3rdparty/ to overwrite pybind11 see above.

5.3 Official solutions to common problems

Link: https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/05_faq.md#difference-between-body_25-vs-coco-vs-mpi

6. Supplement

If you have any questions, please communicate in the comment area. I am happy to answer them. Code words are not easy, please support me; please correct me if I am wrong, thank you!

Guess you like

Origin blog.csdn.net/SuiJiangPiaoLiu/article/details/126434521