相关链接:
1、项目gayhub:https://github.com/CMU-Perceptual-Computing-Lab/openpose
2、官方BVLC版本Caffe:https://github.com/BVLC/caffe
3、openpose指定的CMU版本Caffe:https://github.com/CMU-Perceptual-Computing-Lab/caffe
4、openpose的ros项目包:https://github.com/firephinx/openpose_ros
5、电脑环境配置:9代i5+1660Ti、ubuntu18.04、nvidia418.74、cuda10.0.130、anaconda 4.3.0、tensorflow-gpu 1.13.1、opencv3.4.1、ros-melodic(后来觉得,好像可以不用anaconda)
6、openpose速度优化:https://www.aiuai.cn/aifarm715.html
- Ubuntu18.04 安装nvidia驱动、cuda、cudnn、tensorflow(GPU版)
- Ubuntu、Anaconda下编译opencv和opencv_contrib(with cuda)
- Anaconda和ROS联合使用
一、前提:caffe
1、依赖库
sudo apt-get --assume-yes install build-essential
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
# Python libs
sudo -H pip install --upgrade numpy protobuf
2、caffe编译及测试
我先用的caffe是BVLC官方版本https://github.com/BVLC/caffe,编译过程略。
编译前记得修改Makefile.config文件,最后对caffe进行测试,能用
[email protected]:~/caffe$ sudo make runtest #caffe测试通过
注意:与caffe相关的两种openpose编译方式
参考https://blog.csdn.net/qq_33764934/article/details/103406443 openpose 的编译需要caffe,若caffe未单独编译过则down下来解压放于openpose/3rdparty/caffe。openpose它编译时本身默认cmake的参数 BUILD_CAFFE 就是 ON,会编译openpose/3rdparty/caffe路径中的caffe,即下参数的第一种:联合caffe编译。
- 联合caffe编译
#第一种,联合caffe编译:caffe未单独编译过,需要down下来解压放于openpose/3rdparty/caffe cmake -DOpenCV_CONFIG_FILE=/home/muxi/opencv_cuda_anacondabase/opencv-3.4.1/build/OpenCVConfig.cmake -DPROFILER_ENABLED=ON -DBUILD_PYTHON=ON WITH_OPENCV_WITH_OPENGL ..
- link外部caffe编译
cmake的参数通过cmake-gui编译更方便,但是我下载不了有问题,于是就直接将参数写入cmake命令中,对openpose进行无cmake-gui图形界面的cmake。#第二种,link外部caffe编译:caffe放在其他路径单独编译过 cmake -DOpenCV_CONFIG_FILE=/home/muxi/opencv_cuda_anacondabase/opencv-3.4.1/build/OpenCVConfig.cmake -DCaffe_INCLUDE_DIRS="/home/muxi/caffe/include;/home/muxi/caffe/build/include" -DCaffe_LIBS=/home/muxi/caffe/build/lib/libcaffe.so -DBUILD_CAFFE=OFF -DPROFILER_ENABLED=ON -DBUILD_PYTHON=ON WITH_OPENCV_WITH_OPENGL ..
二、openpose的编译
考虑到官方文档openpose/doc/prerequisites.md里的警告“Anaconda should not be installed on your system. Anaconda includes a Protobuf version that is incompatible with Caffe. Either you uninstall anaconda and install protobuf via apt-get, or you compile your own Caffe and link it to OpenPose.” 说若已安装anaconda,在编译openpose时需要单独link外部编译好的caffe。于是看到这里,考虑用link外部caffe编译吧。
1、link外部caffe编译
重新clone个openpose
##下载openpose
[email protected]:~/gesture_recognition/October$ git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose.git
#下载指定caffe
#[email protected]:~/gesture_recognition/October/openpose/3rdparty$ git clone https://github.com/CMU-Perceptual-Computing-Lab/caffe
编译时需要将~/caffe里原先编译好的caffe链接进来,也就是用cmake命令的第二种:link外部caffe编译
#编译
[email protected]:~/gesture_recognition/October/openpose/build$ cmake -DOpenCV_CONFIG_FILE=/home/muxi/opencv_cuda_anacondabase/opencv-3.4.1/build/OpenCVConfig.cmake -DCaffe_INCLUDE_DIRS="/home/muxi/caffe/include;/home/muxi/caffe/build/include" -DCaffe_LIBS=/home/muxi/caffe/build/lib/libcaffe.so -DBUILD_CAFFE=OFF -DPROFILER_ENABLED=ON -DBUILD_PYTHON=ON ..
[email protected]:~/gesture_recognition/October/openpose/build$ make -j`nproc`
[email protected]:~/gesture_recognition/October/openpose/build$ sudo make install
#运行测试
[email protected]:~/gesture_recognition/October/openpose$ ./build/examples/openpose/openpose.bin --model_pose BODY_25 --render_pose 1 --net_resolution "800x320" --number_people_max 1
编译正常,运行报错 [libprotobuf ERROR google/protobuf/message_lite.cc:118] Can't parse message of type "caffe.NetParameter" because it is missing required fields: layer[0].clip_param.min, layer[0].clip_param.max
参考https://blog.csdn.net/blgpb/article/details/87925768 说caffe不能是caffe官方提供的caffe(https://github.com/BVLC/caffe),需要OpenPose官方支持的版本(https://github.com/CMU-Perceptual-Computing-Lab/caffe)
2、联合caffe编译
还是换成联合caffe编译吧!不必删除系统中原有的Caffe安装此Caffe版本,可以直接在编译OpenPose时开启BUILD_CAFFE=ON功能。于是,下载caffe到openpose/3rdparty,用第一种联合caffe编译来cmake,openpose的例程能成功,但帧数真低,更别提移植在无GPU的NUC上,够呛啊。
博主小姐姐
三、ROS上的openpose姿态识别
1、ros环境搭建
本电脑跑通了,不过要部署实际项目需要ros,先建立ros的workspace(土老冒的我还是用的ros1)。
anaconda和ros共存是个坑啊,我安装anaconda环境后ros就用不了了,后来重装ros了,参考Anaconda和ROS联合使用
#建立ros的workspace
mkdir -p catkin_openpose/src
cd catkin_openpose/src
catkin_init_workspace #生成catkin_openpose/src/CMakeList.txt
cd ..
catkin_make #编译生成catkin_openpose/build/和catkin_openpose/devel/
#创建功能包
#cd src
#catkin_create_pkg bagname std_msgs roscpp rospy #后面仨是包的依赖
2、openpose_ros包的下载
官方给出俩ROS examples。
- https://github.com/ravijo/ros_openpose
- https://github.com/firephinx/openpose_ros
先试star最多的第2个包,come on试试就逝世:
[email protected]:~/gesture_recognition/catkin_openpose/src$ git clone https://github.com/firephinx/openpose_ros.git
clone下来是以下两个包,这俩包要直接放到catkin_openpose/src路径里。
3、openpose_ros包编译
在openpose_ros/src/openpose_flags.cpp里修改openpose的路径为之前编译好的openpose的路径为~/gesture_recognition/October/openpose/models/如下:
DEFINE_string(model_folder, "~/gesture_recognition/October/openpose/models/", "Folder path (absolute or relative) where the models (pose, face, ...) are located.");
输入openpose的图像的话题名是/camera/image,可以在openpose_ros/launch/openpose_ros.launch中修改。
[email protected]:~/gesture_recognition/catkin_openpose$ catkin_make
4、openpose_ros运行及报错
ros包编译成功后,运行
rosrun openpose_ros openpose_ros_node
会报错 /home/muxi/gesture_recognition/catkin_openpose/devel/lib/openpose_ros/openpose_ros_node: error while loading shared libraries: libcaffe.so.1.0.0: cannot open shared object file: No such file or directory
原因可能是:link外部caffe编译出错后,换成联合caffe编译了,忽视了第二步警告(已安装anaconda,在编译openpose时需要单独link外部编译好的caffe),即使联合caffe编译openpose后demo也能跑通。
预计解决方式:仍然该使用link外部caffe的方式编译openpose,而不是联合caffe编译。可试试不链接caffe官方版本,而是外部链接编译好的CMU版本的caffe,来编译openpose。
openpose帧数太低了,考虑实际工程算力,换个姿态识别项目吧。