构建openpose docker环境
1.确保你的linux系统已经安装了docker2.拉取镜像 docker pull cwaffles/openpose3.构建容器并且进入交互式命令docker run -it [镜像ID] /bin/bash4.build python openpose$ cd /openpose/build/python/openpose$ make install5.setup env. for pyop
1.确保你的linux系统已经安装了docker
2.拉取镜像 docker pull cwaffles/openpose
3.构建容器并且进入交互式命令 docker run -it [镜像ID] /bin/bash
4.build python openpose
$ cd /openpose/build/python/openpose
$ make install
5.setup env. for pyopenpose
$ cd /openpose/build/python/openpose
$ cp ./pyopenpose.cpython-36m-x86_64-linux-gnu.so /usr/local/lib/python3.6/dist-packages
$ cd /usr/local/lib/python3.6/dist-packages
$ ln -s pyopenpose.cpython-36m-x86_64-linux-gnu.so pyopenpose
$ export LD_LIBRARY_PATH=/openpose/build/python/openpose
$ python3
>>> import pyopenpose as op
>>>
6.run examples
# download model
$ cd /openpose/models
$ bash getModels.sh
# test python examples
$ cd /openpose/examples/tutorial_api_python
# please follow this commit to fix code(https://github.com/u0251077/openpose-docker/commit/f7cb071b6cca51de7c0404e064b4344eb1c075df)
$ python3 01_body_from_image.py
7.程序中有bug,需要改正一下代码,我这里上传到了docker容器里一个测试程序。
import os
import sys
from sys import platform
import argparse
import pyopenpose as op
try:
"""
# Import Openpose (Windows/Ubuntu/OSX)
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# Windows Import
if platform == "win32":
# Change these variables to point to the correct folder (Release/x64 etc.)
sys.path.append(dir_path + '/../../python/openpose/Release');
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../../x64/Release;' + dir_path + '/../../bin;'
import pyopenpose as op
else:
# Change these variables to point to the correct folder (Release/x64 etc.)
sys.path.append('../../python');
# If you run `make install` (default path is `/usr/local/python` for Ubuntu), you can also access the OpenPose/python module from there. This will install OpenPose and the python library at your desired installation path. Ensure that this is in your python path in order to use it.
# sys.path.append('/usr/local/python')
from openpose import pyopenpose as op
except 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 e
"""
# Flags
parser = argparse.ArgumentParser()
#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.).")
args = parser.parse_known_args()
# Custom Params (refer to include/openpose/flags.hpp for more parameters)
params = dict()
#params["model_folder"] = "../../../models/"
params["model_folder"] = "../../models/"
# Add others in path?
for i in range(0, len(args[1])):
curr_item = args[1][i]
if i != len(args[1])-1: next_item = args[1][i+1]
else: next_item = "1"
if "--" in curr_item and "--" in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = "1"
elif "--" in curr_item and "--" not in next_item:
key = curr_item.replace('-','')
if key not in params: params[key] = next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
# Process Image
datum = op.Datum()
imageToProcess = cv2.imread(args[0].image_path)
datum.cvInputData = imageToProcess
opWrapper.emplaceAndPop([datum])
# Display Image
print("Body keypoints: \n" + str(datum.poseKeypoints))
cv2.imshow("OpenPose 1.6.0 - Tutorial Python API", datum.cvOutputData)
cv2.waitKey(0)
cv2.imwrite("result_body.jpg", datum.cvOutputData)
#cv2.imshow("OpenPose 1.6.0 - Tutorial Python API", datum.cvOutputData)
#cv2.waitKey(0)
except Exception as e:
print(e)
sys.exit(-1)
测试结果:输出一堆关节点坐标。
<pre>root@2742293aa376:/openpose/examples/tutorial_api_python# python3 example_code.py
Starting OpenPose Python Wrapper...
Auto-detecting all available GPUs... Detected 1 GPU(s), using 1 of them starting at GPU 0.
Body keypoints:
[[[3.2809854e+02 2.1974371e+02 7.5993967e-01]
[3.2289130e+02 2.1718504e+02 8.3385360e-01]
[2.9802701e+02 2.2368245e+02 8.8920242e-01]
[2.7715598e+02 2.5109933e+02 8.6595273e-01]
[2.9809534e+02 2.7328116e+02 8.2083827e-01]
[3.4900360e+02 2.1327135e+02 9.2912471e-01]
[3.6726160e+02 2.3550529e+02 8.7097746e-01]
[3.6850781e+02 2.6154324e+02 8.3065987e-01]
[3.2806213e+02 2.8759146e+02 8.6716896e-01]
[3.1245990e+02 2.8764346e+02 7.8310686e-01]
[3.2936475e+02 3.3851541e+02 8.6039579e-01]
[3.3854834e+02 3.9202173e+02 7.7205557e-01]
[3.3985031e+02 2.8631238e+02 8.6554557e-01]
[3.4376807e+02 3.3462039e+02 7.7605212e-01]
[3.4638205e+02 3.7248010e+02 6.3853985e-01]
[3.2416013e+02 2.1451590e+02 6.8749976e-01]
[3.3074908e+02 2.1451418e+02 6.3172626e-01]
[3.1632730e+02 2.0415282e+02 7.0270222e-01]
[3.3860080e+02 2.0545940e+02 2.5160685e-01]
[3.5936539e+02 3.8163797e+02 3.0262479e-01]
[3.5938715e+02 3.8030585e+02 3.8734350e-01]
[3.4764966e+02 3.7510175e+02 3.5746363e-01]
[3.4114755e+02 4.1029895e+02 6.9135833e-01]
[3.3590115e+02 4.0902325e+02 6.3767231e-01]
[3.3981992e+02 3.9857721e+02 5.6923801e-01]]
[[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[4.2074823e+02 3.0593616e+02 8.6281455e-01]
[4.5077130e+02 3.0857712e+02 8.0427569e-01]
[4.7298636e+02 3.5023221e+02 9.0337217e-01]
[4.4819788e+02 3.6990717e+02 6.9541442e-01]
[3.8944159e+02 2.9939224e+02 8.4941977e-01]
[3.5947684e+02 3.2944754e+02 9.4136912e-01]
[3.8165787e+02 3.5419604e+02 8.3384556e-01]
[4.1292001e+02 3.8290024e+02 7.8305215e-01]
[4.3123010e+02 3.8421210e+02 7.1762729e-01]
[4.2077008e+02 4.4560986e+02 7.9618287e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[3.9596503e+02 3.8159378e+02 7.0373863e-01]
[3.8551382e+02 4.3511887e+02 7.6988512e-01]
[3.7378726e+02 4.7693509e+02 2.2625722e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[4.3515445e+02 2.8369504e+02 6.7381614e-01]
[4.1160095e+02 2.7851880e+02 9.0691555e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[3.7247885e+02 4.7694193e+02 1.0687940e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]]
[[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[4.7818686e+02 2.7064902e+02 8.0004317e-01]
[5.0167981e+02 2.6683105e+02 7.8615856e-01]
[5.0557230e+02 2.8631616e+02 4.1359463e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[4.5605368e+02 2.7328049e+02 8.1177378e-01]
[4.4161093e+02 3.0716895e+02 5.7765806e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[4.7428549e+02 3.3856525e+02 8.4464747e-01]
[4.8600989e+02 3.3856204e+02 8.0585420e-01]
[4.8735986e+02 3.8683725e+02 8.0624354e-01]
[4.9649228e+02 4.4296634e+02 8.5596460e-01]
[4.6247906e+02 3.3857523e+02 7.3071110e-01]
[4.6380847e+02 3.9203394e+02 8.5256344e-01]
[4.6517609e+02 4.4815677e+02 8.0368519e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[4.8732034e+02 2.4456866e+02 2.3870933e-01]
[4.6514789e+02 2.4456361e+02 8.3356500e-01]
[4.4687830e+02 4.4818286e+02 6.0361665e-01]
[4.4946494e+02 4.5209204e+02 6.8886167e-01]
[4.7293256e+02 4.5470789e+02 8.3570737e-01]
[4.9907031e+02 4.4429254e+02 4.9687880e-01]
[5.0562808e+02 4.4431171e+02 5.9700477e-01]
[4.9649667e+02 4.5205167e+02 8.1779170e-01]]
[[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[3.7371924e+00 3.2548853e+02 3.6309335e-01]
[1.6248102e+01 3.3074368e+02 8.2002681e-01]
[2.5341917e+01 3.7768115e+02 8.5994357e-01]
[2.6669228e+01 4.0245346e+02 8.6616194e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[2.0087900e+01 2.9541397e+02 5.8924217e-02]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[1.4901900e+01 2.9680981e+02 8.9045525e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]]
[[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[3.7469666e+00 4.0509769e+02 7.3330581e-02]
[3.7331178e+00 4.0640887e+02 4.0140808e-01]
[3.7368219e+00 4.5732520e+02 4.1400149e-01]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]
[0.0000000e+00 0.0000000e+00 0.0000000e+00]]]
</pre>
更多推荐
所有评论(0)