|
|
|
|
|
import sys |
|
import cv2 |
|
import os |
|
from sys import platform |
|
import argparse |
|
import time |
|
|
|
try: |
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__)) |
|
try: |
|
|
|
if platform == "win32": |
|
|
|
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: |
|
|
|
sys.path.append('../../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 |
|
|
|
|
|
parser = argparse.ArgumentParser() |
|
parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000241.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).") |
|
args = parser.parse_known_args() |
|
|
|
|
|
params = dict() |
|
params["model_folder"] = "../../../models/" |
|
params["hand"] = True |
|
params["hand_detector"] = 2 |
|
params["body"] = 0 |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
opWrapper = op.WrapperPython() |
|
opWrapper.configure(params) |
|
opWrapper.start() |
|
|
|
|
|
imageToProcess = cv2.imread(args[0].image_path) |
|
handRectangles = [ |
|
|
|
[ |
|
op.Rectangle(320.035889, 377.675049, 69.300949, 69.300949), |
|
op.Rectangle(0., 0., 0., 0.), |
|
], |
|
|
|
[ |
|
op.Rectangle(80.155792, 407.673492, 80.812706, 80.812706), |
|
op.Rectangle(46.449715, 404.559753, 98.898178, 98.898178), |
|
], |
|
|
|
[ |
|
op.Rectangle(185.692673, 303.112244, 157.587555, 157.587555), |
|
op.Rectangle(88.984360, 268.866547, 117.818230, 117.818230), |
|
] |
|
] |
|
|
|
|
|
datum = op.Datum() |
|
datum.cvInputData = imageToProcess |
|
datum.handRectangles = handRectangles |
|
|
|
|
|
opWrapper.emplaceAndPop(op.VectorDatum([datum])) |
|
print("Left hand keypoints: \n" + str(datum.handKeypoints[0])) |
|
print("Right hand keypoints: \n" + str(datum.handKeypoints[1])) |
|
cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData) |
|
cv2.waitKey(0) |
|
except Exception as e: |
|
print(e) |
|
sys.exit(-1) |
|
|