forked from CMU-Perceptual-Computing-Lab/openpose
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenpose_python.py
More file actions
Latest commit
60 lines (54 loc) · 2.48 KB
/
Copy pathopenpose_python.py
File metadata and controls
60 lines (54 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# From Python
# It requires OpenCV installed for Python
importsys
importcv2
importos
fromsysimportplatform
importargparse
try:
# Import Openpose (Windows/Ubuntu/OSX)
dir_path=os.path.dirname(os.path.realpath(__file__))
try:
# Windows Import
ifplatform=="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;'
importpyopenposeasop
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')
fromopenposeimportpyopenposeasop
exceptImportErrorase:
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
raisee
# 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.).")
args=parser.parse_known_args()
# Custom Params (refer to include/openpose/flags.hpp for more parameters)
params=dict()
params["model_folder"] ="../../../models/"
# Add others in path?
foriinrange(0, len(args[1])):
curr_item=args[1][i]
ifi!=len(args[1])-1: next_item=args[1][i+1]
else: next_item="1"
if"--"incurr_itemand"--"innext_item:
key=curr_item.replace('-','')
ifkeynotinparams: params[key] ="1"
elif"--"incurr_itemand"--"notinnext_item:
key=curr_item.replace('-','')
ifkeynotinparams: params[key] =next_item
# Construct it from system arguments
# op.init_argv(args[1])
# oppython = op.OpenposePython()
# Starting OpenPose
opWrapper=op.WrapperPython(3)
opWrapper.configure(params)
opWrapper.execute()
exceptExceptionase:
print(e)
sys.exit(-1)