前言
最近准备看看rtpose
的代码,发现已经由openpose
这个项目维护着了,由于经常在windows
下调试代码,所以尝试了一下如何在windows
下编译openpose
源码,整体来说非常简单的。
国际惯例,参考博客:
[OpenPose]的主页
[OpenPose]的windows版本,截止到写博客最新版本是v1.70
官方安装说明
【注】强烈建议解压目录路径不要太长,比如解压在E:\code
下,不要解压在E:\code\xx\xx\xx\xx_xxx
之类的,我自己尝试的时候给我弹一堆问题。
准备工作
使用工具
CMake`,`Visual Studio`,`CUDA`,`cudnn
具体地,我用的具体版本是:
CMake
: 3.17.3
Visual Studio
:建议2013以上,我用的2017
CUDA
: 10.0
cudnn
:cudnn-10.0-windows10-x64-v7.6.3.30
关于CUDA的安装就不说了,可以看别人博客,也可以看我配置caffe的时候配置CUDA的方法
【注】无需再下载opencv、caffe之类的东东了,只需要保证你的网络良好,cmake的时候会自动下载,不过我也会针对下载的东西在网盘立马提供备份链接,供网络不好的大哥们下载。
下载工程
直接用git命令行模式:
git clone --recursive https://github.com/CMU-Perceptual-Computing-Lab/openpose.git
或者按照官网说的:
git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose
cd openpose/
git submodule update --init --recursive --remote
一定要注意使用--recursive
模式,不然不会在openpose/3rdparty/caffe
目录下自动下载作者DIY
的caffe
工程。
我的这一步上传到了:链接:https://pan.baidu.com/s/1UuSVFk2F3C9qeWGh3jkaZw 提取码:ow7t
生成工程文件
接下来直接到CMake
里编译生成VS
工程:
建议保持默认,暂时不要勾选BUILD_UNITY_SUPPORT
和BUILD_PYTHON
,避免出错无法排查。如果CMAKE出错,建议和我上面的截图核对一下,哪里出问题可以贴在评论区或者私信我,这样能够定位问题。
同时我也把CMake
的log
贴出来看看:
Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18363.
The C compiler identification is MSVC 19.16.27043.0
The CXX compiler identification is MSVC 19.16.27043.0
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMAKE_VERSION = 3.17.3
Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0 (found version "10.0")
Building with CUDA.
Downloading windows dependencies...
Downloading http://posefs1.perception.cs.cmu.edu/OpenPose/3rdparty/windows/opencv_450_v15_2020_11_18.zip...
Extracting D:/code/C++/openpose/3rdparty/windows/opencv_450_v15_2020_11_18.zip...
Downloading http://posefs1.perception.cs.cmu.edu/OpenPose/3rdparty/windows/caffe3rdparty_16_2020_11_14.zip...
Extracting D:/code/C++/openpose/3rdparty/windows/caffe3rdparty_16_2020_11_14.zip...
Downloading http://posefs1.perception.cs.cmu.edu/OpenPose/3rdparty/windows/caffe_16_2020_11_14.zip...
Extracting D:/code/C++/openpose/3rdparty/windows/caffe_16_2020_11_14.zip...
Windows dependencies downloaded.
Adding Example Calibration
Adding Example tutorial_add_module_custom_post_processing
Adding Example tutorial_api_thread_1_user_processing_function
Adding Example tutorial_api_thread_2_user_input_processing_output_and_datum
Adding Example OpenPoseDemo
Adding Example 01_body_from_image_default
Adding Example 02_whole_body_from_image_default
Adding Example 03_keypoints_from_image
Adding Example 04_keypoints_from_images
Adding Example 05_keypoints_from_images_multi_gpu
Adding Example 06_face_from_image
Adding Example 07_hand_from_image
Adding Example 08_heatmaps_from_image
Adding Example 09_keypoints_from_heatmaps
Adding Example 10_asynchronous_custom_input
Adding Example 11_asynchronous_custom_input_multi_camera
Adding Example 12_asynchronous_custom_output
Adding Example 13_asynchronous_custom_input_output_and_datum
Adding Example 14_synchronous_custom_input
Adding Example 15_synchronous_custom_preprocessing
Adding Example 16_synchronous_custom_postprocessing
Adding Example 17_synchronous_custom_output
Adding Example 18_synchronous_custom_all_and_datum
Download the models.
Downloading BODY_25 model...
NOTE: This process might take several minutes depending on your internet connection.
Not downloading body (COCO) model
Not downloading body (MPI) model
Downloading face model...
NOTE: This process might take several minutes depending on your internet connection.
Downloading hand model...
NOTE: This process might take several minutes depending on your internet connection.
Models Downloaded.
Configuring done
然后再cmake
里面再generate
一下,就可以Open Project
了。
或者Genrate
完毕以后,在openpose/build
下就能看到openpose.sln
文件了,打开就行。
【注】有时候由于网络原因,下载文件会失败,导致生成失败或者编译不成功,可以手动下载:
pose_iter_584000.caffemodel,放入\openpose\models\pose\body_25
pose_iter_440000.caffemodel,放入\openpose\models\pose\coco
pose_iter_160000.caffemodel,放入\openpose\models\pose\mpi
pose_iter_116000.caffemodel,放入\openpose\models\face
pose_iter_102000.caffemodel,放入\openpose\models\hand
三方库(放到\openpose\3rdparty\windows
,解压方式选择解压到当前文件夹):
caffe_cpu_2018_05_27:链接:https://pan.baidu.com/s/1qjya7lWbj8jXu_8Hx4t5JQ 提取码:873e
caffe_16_2020_11_14:链接:https://pan.baidu.com/s/1Itu_C_8gWbHlGr1AMBaM1Q 提取码:hl6y
opencv_450_v15_2020_11_18:链接:https://pan.baidu.com/s/1yjmTCU11m1yjIoz4RrtotQ 提取码:bq1r
caffe3rdparty_16_2020_11_14:链接:https://pan.baidu.com/s/16kGyDG9Xwsun_wvnACU4Zw 提取码:ccsi
编译工程
注意我们CMake
时候选了x64
,所以打开的VS
工程也是默认DEBUG x64
。再次提示我用的VS2017
直接对着整个工程ALL_BUILD
生成即可,如果出错,请把错误在评论区或者私信指出。
生成完毕可以在openpose/build/x64/Debug
下看到很多生成的exe
,代表成功了。
然后将你想测试的项目设置成启动项
接下来运行就行;如果这里运行报错,建议直接使用CPU
版本,方法就CMAKE
里面的GPU_MODE
改成CPU_ONLY
,USE_CUDNN
选项去掉。
整个工程的文件也打包放到百度云了:
链接:https://pan.baidu.com/s/1c8BwQvEhycjwEARcRjZZwA
提取码:9v3u
后记
这个代码工程比较大,其实我个人建议跑rtpose
的代码,虽然配置有点难度,但是源码看着很清晰。这个回头再说,下一篇博客可能就是解析openpose
的前身rtpose
的论文了:Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields
即将参考的博客是:Human pose estimation using OpenPose with TensorFlow
【更新日志2020-1-15】
这里有一个超级简单的,基于opencv调用openpose的caffe模型,实现多人姿态估计的代码:
https://github.com/spmallick/learnopencv/tree/master/OpenPose-Multi-Person
公众号已同步本篇博客,如有问题可直接评论或公众号私聊。