@@ -11,14 +11,14 @@ OpenPose Python Module and Demo
## Introduction
This experimental module exposes a Python API for OpenPose. This allows you to construct an OpenPose object, pass in a numpy array for an image, and get a numpy array of the pose positions. This API also exposes an API that allows you to directly pass in heatmaps from a network and extract poses out of it (Requires Python Caffe to be installed seperately)
At present the Python API only supports body pose. Hands and Face will be added in the future.
This module exposes a Python API for OpenPose. It is effectively a wrapper that replicates most of the functionality of the [op::Wrapper class](https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/include/openpose/wrapper/wrapper.hpp) and allows you to populate and retrieve data from the [op::Datum class](https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/include/openpose/core/datum.hpp) using standard Python and Numpy constructs.
## Compatibility
The OpenPose Python module is compatible with both Python 2 and Python 3. In addition, it will also run in all OpenPose compatible operating systems.
The OpenPose Python module is compatible with both Python 2 and Python 3. In addition, it will also run in all OpenPose compatible operating systems. It uses [Pybind11](https://github.com/pybind/pybind11) for mapping between C++ and Python datatypes.
To compile, enable `BUILD_PYTHON` in cmake. Pybind selects the latest version of Python by default (Python 3). To use Python 2, change `PYTHON_EXECUTABLE` and `PYTHON_LIBRARY` flags in cmake to your desired python version.
...
...
@@ -28,22 +28,18 @@ Check [doc/installation.md#python-module](../installation.md#python-api) for ins
The Python API requires Numpy for array management, and OpenCV for image loading. They can be installed via:
```
pip install numpy
pip install opencv-python
pip install numpy opencv-python
```
## Testing
Two examples can be found in `build/examples/tutorial_api_python` in your build folder. Navigate directly to this path to run examples.
-`1_extract_pose` demonstrates a simple use of the API.
-`2_pose_from_heatmaps` demonstrates constructing pose from heatmaps from the caffe network (Requires Python Caffe to be installed seperately, only tested on Ubuntu).
All the Python examples from the Tutorial API Python module can be found in `build/examples/tutorial_api_python` in your build folder. Navigate directly to this path to run examples.
```
# From command line
cd build/examples/tutorial_api_python
python 1_extract_pose.py
python3 1_body_from_image.py
```
...
...
@@ -51,5 +47,5 @@ python 1_extract_pose.py
## Exporting Python OpenPose
Note: This step is only required if you are moving the `*.py` files outside their original location, or writting new `*.py` scripts outside `build/examples/tutorial_api_python`.
- Option a, installing OpenPose: On an Ubuntu or OSX based system, you could install OpenPose by running `sudo make install`, you could then set the OpenPose path in your python scripts to the OpenPose installation path (default: `/usr/local/python`) and start using OpenPose at any location. Take a look at `build/examples/tutorial_pose/1_extract_pose.py` for an example.
- Option b, not installing OpenPose: To move the OpenPose Python API demos to a different folder, ensure that the line `sys.path.append('{OpenPose_path}/python')` is properly set in your `*.py` files, where `{OpenPose_path}` points to your build folder of OpenPose. Take a look at `build/examples/tutorial_pose/1_extract_pose.py` for an example.
- Option a, installing OpenPose: On an Ubuntu or OSX based system, you could install OpenPose by running `sudo make install`, you could then set the OpenPose path in your python scripts to the OpenPose installation path (default: `/usr/local/python`) and start using OpenPose at any location. Take a look at `build/examples/tutorial_pose/1_body_from_image.py` for an example.
- Option b, not installing OpenPose: To move the OpenPose Python API demos to a different folder, ensure that the line `sys.path.append('{OpenPose_path}/python')` is properly set in your `*.py` files, where `{OpenPose_path}` points to your build folder of OpenPose. Take a look at `build/examples/tutorial_pose/1_body_from_image.py` for an example.
# 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')
fromopenposeimportopenposeasop
except:
raiseException('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)
# 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')
# Parameters for OpenPose. Take a look at C++ OpenPose example for meaning of components. Ensure all below are filled
try:
fromopenposeimport*
except:
raiseException('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
params=dict()
params["logging_level"]=3
params["output_resolution"]="-1x-1"
params["net_resolution"]="-1x368"
params["model_pose"]="BODY_25"
params["alpha_pose"]=0.6
params["scale_gap"]=0.25
params["scale_number"]=1
params["render_threshold"]=0.05
# If GPU version is built, and multiple GPUs are available, set the ID here
params["num_gpu_start"]=0
params["disable_blending"]=False
# Ensure you point to the correct path where models are located
# 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')
fromopenposeimportopenposeasop
except:
raiseException('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)
# 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')
fromopenposeimportopenposeasop
except:
raiseException('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)
# 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')
fromopenposeimportopenposeasop
except:
raiseException('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)