# the original openpose script
# command line argument:
# --image_dir: the folder that contains the input images to be read in
# --write_images: the folder to store the image output with poses
# --write_json: the folder to store the json output
# --video: the input video to be read in
# --write_video: the folder to store the video output with poses
# --camera: to select which camera to use (2 for our Intel realsense RGB camera)
# From Python
# It requires OpenCV installed for Python
import sys
import cv2
import os
from sys import platform
import argparse
try:
# Import Openpose (Windows/Ubuntu/OSX)
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
# Change these variables to point to the correct folder (Release/x64 etc.)
sys.path.append(dir_path + '/../openpose/bin/python/openpose/Release');
os.environ['PATH'] = os.environ['PATH'] + ';' + dir_path + '/../openpose/x64/Release;' + dir_path + '/../openpose/bin;'
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()
args = parser.parse_known_args()
# Custom Params (refer to include/openpose/flags.hpp for more parameters)
params = dict()
params["model_folder"] = "openpose/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(op.ThreadManagerMode.Synchronous)
opWrapper.configure(params)
opWrapper.execute()
except Exception as e:
print(e)
sys.exit(-1)