OpenPose Python API调用:ImportError: cannot import name 'pyopenpose' from 'openpose'

OpenPose Python API 调用方法

  1. cmake-gui选项中勾选BUILD_PYTHON选项
  2. cd build
  3. sudo make -j‘’
  4. sudo make install
  5. cd ~/your_openpose_dir/examples/tutorial_api_python
  6. python3 01_body_from_image.py

可能出现的错误

  • Error: OpenPose library could not be found. Did you enableBUILD_PYTHONin CMake and have this Python script in the right folder?
  • 在这里插入代码片
  • ImportError: cannot import name 'pyopenpose' from 'openpose'
  • 上面的错误代表.py文件中from openpose import pyopenpose as op未执行成功
  • 首先进入自己的python3 运行环境,依次运行以下命令
  • ls /usr/local/python/openpose 观察是否有文件 pyopenpose.cpython-35m-x86_64-linux-gnu.so* 如果没有 进入build执行sudo make install
  • 如果有pyopenpose.cpython-35m-x86_64-linux-gnu.so进行下面操作
  • import sys
  • sys.path
  • 观察输出,是否有pyopenpose.cpython-35m-x86_64-linux-gnu.so所在目录
  • 若没有,则在源代码py文件中加入sys.path.append('/usr/local/python/openpose')
  • 另一种情况,如下图log
    输出
  • 从上图可以发现目前python3关键字指向的是home下的anaconda
  • 但是OpenPose默认编译的是/usr/local/python目录下的pyopenpose.cpython-35m-x86_64-linux-gnu.so*文件,使用的是系统python解释器
  • sudo vim ~/.bashrc
  • 发现这么一句话:export PATH=/home/ubuntu/anaconda3/bin:$PATH
  • Now,everything is clear,这里声明了anaconda3下的python为默认解释器
  • 在~/.bashrc中加入语句:alias py35=/usr/bin/python3.5 指定py35为系统python3.5的别称
  • source ~/.bashrc
  • 重新运行py35 01_body_from_image.py
  • done…

参考链接灵感来自于此issue

新错误

Error:
Prototxt file not found: ../../../models/pose/body_25/pose_deploy.prototxt.
Possible causes:
	1. Not downloading the OpenPose trained models.
	2. Not running OpenPose from the same directory where the `model` folder is located.
	3. Using paths with spaces.

解决:

vim 01_body_from_image.py

修改第38行params["model_folder"] = "../../../models/"为`

params["model_folder"] = "../../models/"

新错误

a bytes-like object is required, not 'NoneType'

解决:

修改第33行parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000192.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")

parser.add_argument("--image_path", default="../../examples/media/COCO_val2014_000000000192.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")

你可能感兴趣的:(openpose)