| |
| |
| import sys |
| import cv2 |
| import os |
| from sys import platform |
| import argparse |
|
|
|
|
| def display(datums): |
| datum = datums[0] |
| cv2.imshow("OpenPose 1.7.0 - Tutorial Python API", datum.cvOutputData) |
| key = cv2.waitKey(1) |
| return (key == 27) |
|
|
|
|
| def printKeypoints(datums): |
| datum = datums[0] |
| print("Body keypoints: \n" + str(datum.poseKeypoints)) |
| print("Face keypoints: \n" + str(datum.faceKeypoints)) |
| print("Left hand keypoints: \n" + str(datum.handKeypoints[0])) |
| print("Right hand keypoints: \n" + str(datum.handKeypoints[1])) |
|
|
|
|
| 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("--no-display", action="store_true", help="Disable display.") |
| args = parser.parse_known_args() |
|
|
| |
| params = dict() |
| params["model_folder"] = "../../../models/" |
|
|
| |
| 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(op.ThreadManagerMode.AsynchronousOut) |
| opWrapper.configure(params) |
| opWrapper.start() |
|
|
| |
| userWantsToExit = False |
| while not userWantsToExit: |
| |
| datumProcessed = op.VectorDatum() |
| if opWrapper.waitAndPop(datumProcessed): |
| if not args[0].no_display: |
| |
| userWantsToExit = display(datumProcessed) |
| printKeypoints(datumProcessed) |
| else: |
| break |
| except Exception as e: |
| print(e) |
| sys.exit(-1) |
|
|