├── Pose_Estimation.gif ├── README.md └── pose_estimation.py /Pose_Estimation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishagandhi/OpenPose_PythonOpenCV/17c91eb24816e0fd208df4dd230e38d93003c824/Pose_Estimation.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenPose_PythonOpenCV 2 | 3 | This code is implementing this post: https://medium.com/pixel-wise/real-time-pose-estimation-in-webcam-using-openpose-python-2-3-opencv-91af0372c31c 4 | 5 | ![alt text](https://github.com/nishagandhi/OpenPose_PythonOpenCV/blob/master/Pose_Estimation.gif) 6 | 7 | A simple code demonstrating real-time Pose Estimation in webcam using OpenPose Python and OpenCV. 8 | 9 | References: 10 | 11 | [1] https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation.md 12 | 13 | 14 | [2] https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/examples/tutorial_python/1_extract_pose.py 15 | 16 | -------------------------------------------------------------------------------- /pose_estimation.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import cv2 3 | import os 4 | from sys import platform 5 | 6 | dir_path = os.path.dirname(os.path.realpath(__file__)) 7 | sys.path.append('usr/local/python'); 8 | 9 | try: 10 | from openpose import * 11 | except: 12 | 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?') 13 | 14 | def set_params(): 15 | 16 | params = dict() 17 | params["logging_level"] = 3 18 | params["output_resolution"] = "-1x-1" 19 | params["net_resolution"] = "-1x368" 20 | params["model_pose"] = "BODY_25" 21 | params["alpha_pose"] = 0.6 22 | params["scale_gap"] = 0.3 23 | params["scale_number"] = 1 24 | params["render_threshold"] = 0.05 25 | # If GPU version is built, and multiple GPUs are available, set the ID here 26 | params["num_gpu_start"] = 0 27 | params["disable_blending"] = False 28 | # Ensure you point to the correct path where models are located 29 | params["default_model_folder"] = dir_path + "/../../../models/" 30 | return params 31 | 32 | def main(): 33 | 34 | 35 | params = set_params() 36 | 37 | #Constructing OpenPose object allocates GPU memory 38 | openpose = OpenPose(params) 39 | 40 | #Opening OpenCV stream 41 | stream = cv2.VideoCapture(1) 42 | 43 | font = cv2.FONT_HERSHEY_SIMPLEX 44 | 45 | while True: 46 | 47 | ret,img = stream.read() 48 | 49 | # Output keypoints and the image with the human skeleton blended on it 50 | keypoints, output_image = openpose.forward(img, True) 51 | 52 | # Print the human pose keypoints, i.e., a [#people x #keypoints x 3]-dimensional numpy object with the keypoints of all the people on that image 53 | if len(keypoints)>0: 54 | print('Human(s) Pose Estimated!') 55 | print(keypoints) 56 | else: 57 | print('No humans detected!') 58 | 59 | 60 | # Display the stream 61 | cv2.putText(output_image,'OpenPose using Python-OpenCV',(20,30), font, 1,(255,255,255),1,cv2.LINE_AA) 62 | 63 | cv2.imshow('Human Pose Estimation',output_image) 64 | 65 | key = cv2.waitKey(1) 66 | 67 | if key==ord('q'): 68 | break 69 | 70 | stream.release() 71 | cv2.destroyAllWindows() 72 | 73 | 74 | if __name__ == '__main__': 75 | main() 76 | 77 | 78 | 79 | 1,1 Top 80 | 81 | 82 | 83 | --------------------------------------------------------------------------------