问题描述:
openpose编译完成后,如果直接使用pycharm打开openpose\build\examples\tutorial_api_python创建项目运行的话,不会出错。但是当移动openpose文件夹的位置,或者移动build文件夹的位置后,运行就会出现No module named pyopenpose的问题。
解决办法:
在pycharm上新建一个项目test,将openpose内的openpose\build\bin、openpose\models、openpose\build\x64\Debug文件夹复制进来,Openpose\build\python\openpose\Debug下的四个文件也复制进来,否则会报错。(我的openpose是使用Debug模式重新生成解决方案的,如果你用的是Release模式,只需要将地址中的Debug换成Release就行,如:openpose\build\x64\Release)
t.py的代码:
import sysimport cv2import osfrom sys import platform# Import Openpose (Windows/Ubuntu/OSX)dir_path = os.path.dirname(os.path.realpath(__file__))try:# Windows Importif platform == "win32":# 如果在visual studio上编译的时候使用的是Release模式,把Debug换成Releaseos.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + './Debug;' + dir_path + './bin;'import pyopenpose as opelse:# Change these variables to point to the correct folder (Release/x64 etc.)sys.path.append('../../python')from openpose import pyopenpose as opexcept ImportError as e:print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')raise eif __name__ == "__main__":# 设置Openpose模型并初始化params = dict()params["model_folder"] = "./models/"opWrapper, datum = op.WrapperPython(), op.Datum()opWrapper.configure(params)opWrapper.start()datum = op.Datum()# 读取图片imageToProcess = cv2.imread(r'E:\PyCharmProject\Engagement-recognition-using-DAISEE-dataset-master\1.jpg')datum.cvInputData = imageToProcessopWrapper.emplaceAndPop(op.VectorDatum([datum]))# Display Imageprint("Body keypoints: \n" + str(datum.poseKeypoints))cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData)cv2.waitKey(0)
参考:计算机视觉教程7-3:Openpose配置与实践