安装openpose前先安装caffe cpu版 python3
参考:https://mp.csdn.net/console/editor/html/104765522
更新源:
sudo gedit /etc/apt/sources.list
在最后加上
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
然后更新
sudo apt-get update
sudo apt-get upgrade
下载模型:可从别人的网盘下载,放入openpose中的models下
链接:https://pan.baidu.com/s/1h_d0dw8OXJ2Ys4-djgW7BQ 密码:725r
(注意这里面下载的 body_25模型是坏的,(运行时默认body_25)下完了运行时换个模型就好)
也可用命令下载(很慢):
cd models
./getModels.sh
cd ..
在openpose目录下创建build文件夹
回到终端中打开camke界面:cmake-gui
填写openpose源码目录以及build
点击Configure按钮, 选择Unix Makefile和use default native compling,点击finish按钮
点击Generate按钮,只用cpu时出现错误,将CUDA那里改成CPU_ONLY,不勾选cuDnn,
若caffe编译好了,就不需要勾BUIL-CAFFE,直接照着下图填上自己的caffe目录下对应的路径。需要用到pythonAPI时,勾上BUILD_PYTHON。再点击Generate按钮。
过程中无报错,且出现configuring done,中间会出现一些红色的可配置项
如上图所示caffe编译后的目录项填写完成
最后点击Generate按钮,生成build文件
进入到caffe根目录,执行下面语句,不然编译会提示缺少caffe.pb.h :
protoc src/caffe/proto/caffe.proto --cpp_out=.
mkdir include/caffe/proto
mv src/caffe/proto/caffe.pb.h include/caffe/proto
然后进入openpose刚才cmake生成的build目录下,编译open pose:
make -j4
查看:https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/quick_start.md#tracking
进入到open pose的根目录,执行命令:
图片:./build/examples/openpose/openpose.bin --image_dir examples/media/ --net_resolution "80x80"
视频:./build/examples/openpose/openpose.bin --video examples/media/video.avi --net_resolution "160x160"
加上脸和手:--face --hand
换模型:--model_pose COCO
--model_pose MPII
--model_pose MPI_4_layers
./build/examples/openpose/openpose.bin --image_dir examples/media/ --model_pose COCO
./build/examples/openpose/openpose.bin --image_dir examples/media/ --model_pose MPII
./build/examples/openpose/openpose.bin --image_dir examples/media/ --model_pose MPI_4_layers
build下完成编译后,采用 Python API 调用若出现错误:
from . import pyopenpose as pyopenpose
ImportError: cannot import name pyopenpose
解决方法:
[1] - 首先,在 openpose 路径找到文件:build/python/openpose/pyopenpose.cpython-35m-x86_64-linux-gnu.so
;复制该文件到路径:/usr/local/lib/python3.5/dist-packages
.
cd OpenPose_rootpath/build/python/openpose/
sudo cp pyopenpose.cpython-35m-x86_64-linux-gnu.so /usr/local/lib/python3.5/dist-packages/
[2] - 然后,进入路径:/usr/local/lib/python3.5/dist-packages
,创建软连接:
cd /usr/local/lib/python3.5/dist-packages/
sudo ln -s pyopenpose.cpython-35m-x86_64-linux-gnu.so pyopenpose
确认环境变量中 LD_LIBRARY_PATH
包含 /usr/local/lib/python3.5/dist-packages
.
[3] - 最后,在 Python 脚本文件中调用:
import pyopenpose as op
#注:
#原始脚本中是 from openpose import pyopenpose as op,需要修改为上行代码.
API版本更新了,测试下载的API的例子参照新的来修改:https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/examples/tutorial_api_python/01_body_from_image.py
参考:https://blog.csdn.net/Aaron121314/article/details/94573634#comments
参考:https://blog.csdn.net/linhai1028/article/details/79452977?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
参考:https://blog.csdn.net/Aaron121314/article/details/94573634
API错误参考:https://www.aiuai.cn/aifarm1155.html#1.PythonAPI%E7%BC%96%E8%AF%91%E6%97%B6%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3