How to use OpenPose's Python API

I tried to touch OpenPose's Python API, so I will write a memorandum

The procedure for installing the Python API is explained in the following article.

The official Python API sample code can be found here I'm just explaining the sample code, so if you are faster to read the source, I think you should refer to it.

Start of OpenPose

    # Starting OpenPose
    opWrapper = op.WrapperPython()

To start using

The params passed here is a dictionary type. Pass various settings in params for using OpenPose.

For example, the model path is specified as follows

    params = dict()
    params["model_folder"] = "../../../models/"

Below is a list of model parameters and default values.

If you pick something that seems important with your own judgment and prejudice

DEFINE_int32(number_people_max,         -1,             "This parameter will limit the maximum number of people detected, by keeping the people with"
                                                        " top scores. The score is based in person area over the image, body part score, as well as"
                                                        " joint score (between each pair of connected body parts). Useful if you know the exact"
                                                        " number of people in the scene, so it can remove false positives (if all the people have"
                                                        " been detected. However, it might also include false negatives by removing very small or"
                                                        " highly occluded people. -1 will keep them all.");

DEFINE_string(model_pose,               "BODY_25",      "Model to be used. E.g., `BODY_25` (fastest for CUDA version, most accurate, and includes"
                                                        " foot keypoints), `COCO` (18 keypoints), `MPI` (15 keypoints, least accurate model but"
                                                        " fastest on CPU), `MPI_4_layers` (15 keypoints, even faster but less accurate).");

DEFINE_bool(3d,                         false,          "Running OpenPose 3-D reconstruction demo: 1) Reading from a stereo camera system."
                                                        " 2) Performing 3-D reconstruction from the multiple views. 3) Displaying 3-D reconstruction"
                                                        " results. Note that it will only display 1 person. If multiple people is present, it will"
                                                        " fail.");

DEFINE_string(write_json,               "",             "Directory to write OpenPose output in JSON format. It includes body, hand, and face pose"
                                                        " keypoints (2-D and 3-D), as well as pose candidates (if `--part_candidates` enabled).");

DEFINE_string(udp_host,                 "",             "Experimental, not available yet. IP for UDP communication. E.g., ``.");

DEFINE_string(udp_port,                 "8051",         "Experimental, not available yet. Port number for UDP communication.");

Image delivery

Load the image Please note that ** PIL cannot be used, please use OpenCV **.

Officially there is a description as follows

Do not use PIL In order to read images in Python, make sure to use OpenCV (do not use PIL). We found that feeding a PIL image format to OpenPose results in the input image appearing in grey and duplicated 9 times (so the output skeleton appear 3 times smaller than they should be, and duplicated 9 times). Source: OpenPose Python Module and Demo

How to read First, create an object for data transfer with ʻop.Datum () Store the image read by OpenCV indatum.cvInputData And let's pass it as a list to ʻopWrapper.emplaceAndPop ʻOpWrapper.emplaceAndPop` has no return value, but the analysis result (output image, joint position, etc.) is included in the passed datum.

    datum = op.Datum()
    imageToProcess = cv2.imread("image_path")
    datum.cvInputData = imageToProcess

Display of output results

#Joint coordinates
print("Body keypoints:" + str(datum.poseKeypoints))    

#Image showing joints
cv2.imshow("Output Image", datum.cvOutputData

Besides, in datum

datum.faceKeypoints   #Coordinates of each part of the face
datum.handKeypoints[0]#Coordinates of each part on the left hand
datum.handKeypoints[1]#Coordinates of each part on the right hand

Etc. are included in various ways

See below for more information

Recommended Posts

How to use OpenPose's Python API
[Python] How to use Typetalk API
python3: How to use bottle (2)
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
[BigQuery] How to use BigQuery API for Python -Table creation-
Python: How to use async with
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to use bing search api
How to use python zip function
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to install and use pandas_datareader [Python]
[Python] How to use import sys sys.argv
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
[Python2.7] Summary of how to use unittest
python: How to use locals () and globals ()
How to use __slots__ in Python class
How to use "deque" for Python data
How to use Python zip and enumerate
[Python] Understand how to use recursive functions
Summary of how to use Python list
How to use GCP's Cloud Vision API
How to use regular expressions in Python
[Python2.7] Summary of how to use subprocess
How to use is and == in Python
[Blender x Python] How to use modifiers
[Question] How to use plot_surface of python
How to use xml.etree.ElementTree
How to use Python-shell
How to use
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to install python
How to use partial
How to use Bio.Phylo
How to use x-means
How to use