我正在制作一个身体跟踪应用程序,如果用户选择跟踪他们的身体动作,我想在其中运行 Open Pose。OpenPose 二进制文件可以像这样运行:
bin\OpenPoseDemo.exe --write_json 'path\to\dump\output'
因此,在我的 Python 脚本中,我希望有一行代码可以运行 Open Pose,而不必通过打开单独的命令行窗口来要求用户手动运行 OpenPose。为此,我尝试过:
import os
os.popen(r"C:\path\to\bin\OpenPoseDemo.exe --write_json 'C:\path\to\dump\output'")
但这会产生以下错误:
Error:
Could not create directory: 'C:\Users\Admin\Documents\Openpose\. Status error = -1. Does the parent folder exist and/or do you have writing access to that path?
我猜这意味着 OpenPose 只能通过进入子目录所在的openpose
目录来打开。bin
所以,我写了一个包含这一行的 shell 脚本:
bin\OpenPoseDemo.exe --write_json 'C:\path\to\dump\output'
并将其保存run_openpose_binary.sh
在openpose
目录中(即所在的同一目录bin
)。
然后我尝试从我的 Python 脚本中运行这个 shell 脚本,如下所示:
import subprocess
subprocess.call(['sh', r'C:\path\to\openpose\run_openpose_binary.sh'])
这给出了以下错误:
FileNotFoundError: [WinError 2] The system cannot find the file specified
我还尝试了以下方法:
os.popen(r"C:\path\to\openpose\run_openpose_binary.sh")
和
os.system(r"C:\path\to\openpose\run_openpose_binary.sh")
这些不会产生任何错误,而是会弹出一个空白窗口并关闭。
所以,我的问题是,如何从我的 Python 脚本中运行 OpenPoseDemo.exe?