Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
soulslicer authored and gineshidalgo99 committed Feb 8, 2019
1 parent babd890 commit 4d70fdf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
82 changes: 82 additions & 0 deletions examples/tutorial_api_python/09_keypoints_from_heatmaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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 pyopenpose 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 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()
parser.add_argument("--image_path", default="../../../examples/media/COCO_val2014_000000000294.jpg", help="Process an image. Read all standard formats (jpg, png, bmp, etc.).")
args = parser.parse_known_args()

# Load image
imageToProcess = cv2.imread(args[0].image_path)

def get_sample_heatmaps():
params = dict()
params["model_folder"] = "../../../models/"
params["heatmaps_add_parts"] = True
params["heatmaps_add_bkg"] = True
params["heatmaps_add_PAFs"] = True
params["heatmaps_scale"] = 3
params["upsampling_ratio"] = 1
params["body"] = 1

# Starting OpenPose
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()

# Process Image and get heatmap
datum = op.Datum()
imageToProcess = cv2.imread(args[0].image_path)
datum.cvInputData = imageToProcess
opWrapper.emplaceAndPop([datum])
poseHeatMaps = datum.poseHeatMaps.copy()
opWrapper.stop()

return poseHeatMaps

# Get Heatmap
poseHeatMaps = get_sample_heatmaps()

# Starting OpenPose
params = dict()
params["model_folder"] = "../../../models/"
params["body"] = 2 # Disable OP Network
opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()

# Pass Heatmap and Run OP
datum = op.Datum()
datum.cvInputData = imageToProcess
datum.poseNetOutput = poseHeatMaps
opWrapper.emplaceAndPop([datum])

# Display Image
print("Body keypoints: \n" + str(datum.poseKeypoints))
cv2.imshow("OpenPose 1.4.0 - Tutorial Python API", datum.cvOutputData)
cv2.waitKey(0)
1 change: 1 addition & 0 deletions examples/tutorial_api_python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ configure_file(05_keypoints_from_images_multi_gpu.py 05_keypoints_from_images_mu
configure_file(06_face_from_image.py 06_face_from_image.py)
configure_file(07_hand_from_image.py 07_hand_from_image.py)
configure_file(08_heatmaps_from_image.py 08_heatmaps_from_image.py)
configure_file(09_keypoints_from_heatmaps.py 09_keypoints_from_heatmaps.py)
configure_file(openpose_python.py openpose_python.py)
2 changes: 1 addition & 1 deletion python/openpose/openpose_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ PYBIND11_MODULE(pyopenpose, m) {
.def_readwrite("cameraMatrix", &op::Datum::cameraMatrix)
.def_readwrite("cameraExtrinsics", &op::Datum::cameraExtrinsics)
.def_readwrite("cameraIntrinsics", &op::Datum::cameraIntrinsics)
.def_readwrite("poseNetOutput", &op::Datum::elementRendered)
.def_readwrite("poseNetOutput", &op::Datum::poseNetOutput)
.def_readwrite("scaleInputToNetInputs", &op::Datum::scaleInputToNetInputs)
.def_readwrite("netInputSizes", &op::Datum::netInputSizes)
.def_readwrite("scaleInputToOutput", &op::Datum::scaleInputToOutput)
Expand Down

0 comments on commit 4d70fdf

Please sign in to comment.