forked from CMU-Perceptual-Computing-Lab/openpose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python Pybind11 wrapper (CMU-Perceptual-Computing-Lab#1014)
- Loading branch information
1 parent
6a6dd2e
commit 29fc003
Showing
20 changed files
with
699 additions
and
739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "3rdparty/caffe"] | ||
path = 3rdparty/caffe | ||
url = https://github.com/CMU-Perceptual-Computing-Lab/caffe.git | ||
[submodule "3rdparty/pybind11"] | ||
path = 3rdparty/pybind11 | ||
url = https://github.com/pybind/pybind11.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# From Python | ||
# It requires OpenCV installed for Python | ||
import sys | ||
import cv2 | ||
import os | ||
from sys import platform | ||
import argparse | ||
|
||
# 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 _openpose 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 openpose as op | ||
except: | ||
raise Exception('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?') | ||
|
||
# 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? | ||
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)) | ||
while 1: | ||
cv2.imshow("win", datum.cvOutputData) | ||
cv2.waitKey(15) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# From Python | ||
# It requires OpenCV installed for Python | ||
import sys | ||
import cv2 | ||
import os | ||
from sys import platform | ||
import argparse | ||
|
||
# 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 _openpose 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 openpose as op | ||
except: | ||
raise Exception('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?') | ||
|
||
# Flags | ||
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() | ||
|
||
# Custom Params (refer to include/openpose/flags.hpp for more parameters) | ||
params = dict() | ||
params["model_folder"] = "../../../models/" | ||
params["face"] = True | ||
params["hand"] = True | ||
|
||
# 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)) | ||
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])) | ||
while 1: | ||
cv2.imshow("win", datum.cvOutputData) | ||
cv2.waitKey(15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# From Python | ||
# It requires OpenCV installed for Python | ||
import sys | ||
import cv2 | ||
import os | ||
from sys import platform | ||
import argparse | ||
import numpy as np | ||
|
||
# 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 _openpose 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 openpose as op | ||
except: | ||
raise Exception('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?') | ||
|
||
# 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/" | ||
params["heatmaps_add_parts"] = True | ||
params["heatmaps_add_PAFs"] = True | ||
|
||
# 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]) | ||
|
||
# Process outputs | ||
outputImageF = (datum.inputNetData[0].copy())[0,:,:,:] + 0.5 | ||
outputImageF = cv2.merge([outputImageF[0,:,:], outputImageF[1,:,:], outputImageF[2,:,:]]) | ||
outputImageF = (outputImageF*255.).astype(dtype='uint8') | ||
heatmaps = datum.poseHeatMaps.copy() | ||
heatmaps = (heatmaps*255.).astype(dtype='uint8') | ||
|
||
# Display Image | ||
counter = 0 | ||
while 1: | ||
num_maps = heatmaps.shape[0] | ||
heatmap = heatmaps[counter, :, :].copy() | ||
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) | ||
combined = cv2.addWeighted(outputImageF, 0.5, heatmap, 0.5, 0) | ||
cv2.imshow("win", combined) | ||
cv2.waitKey(-1) | ||
counter += 1 | ||
counter = counter % num_maps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
### Add Python Test | ||
configure_file(1_extract_pose.py 1_extract_pose.py) | ||
configure_file(openpose_python.py openpose_python.py) | ||
configure_file(1_body_from_image.py 1_body_from_image.py) | ||
configure_file(2_whole_body_from_image.py 2_whole_body_from_image.py) | ||
configure_file(3_heatmaps_from_image.py 3_heatmaps_from_image.py) |
Oops, something went wrong.