From a495480df115b574ba79cc16f9fda92c37cc11e8 Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Fri, 29 Jun 2018 17:15:41 -0400 Subject: [PATCH] Python working with non-default OpenPose --- CMakeLists.txt | 10 +++++-- doc/modules/python_module.md | 29 +++++++++++-------- examples/tutorial_python/1_extract_pose.py | 5 +++- .../tutorial_python/2_pose_from_heatmaps.py | 5 +++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eeae1df6..73ffb6e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -538,15 +538,21 @@ if (WIN32) file(GLOB CAFFE_DLL "${CMAKE_SOURCE_DIR}/3rdparty/windows/caffe_cpu/bin/*.dll") endif () # Caffe 3rd-party DLLs - file(GLOB OPENCV3PTY_DLL "${CMAKE_SOURCE_DIR}/3rdparty/windows/caffe3rdparty/lib/*.dll") + file(GLOB CAFFE_3RD_PARTY_DLL "${CMAKE_SOURCE_DIR}/3rdparty/windows/caffe3rdparty/lib/*.dll") # OpenCV DLLs file(GLOB OPENCV_DLL "${CMAKE_SOURCE_DIR}/3rdparty/windows/opencv/x64/vc14/bin/*.dll") + # GLUT DLLs + file(GLOB GLUT_DLL "${CMAKE_SOURCE_DIR}/3rdparty/windows/freeglut/bin/*.dll") + # Spinnaker DLLs and other files + file(GLOB SPINNAKER_DLL "${CMAKE_SOURCE_DIR}/3rdparty/windows/spinnaker/bin/*") # Copy DLLs into same folder set(BIN_FOLDER ${CMAKE_BINARY_DIR}/bin) file(MAKE_DIRECTORY ${BIN_FOLDER}) file(COPY ${CAFFE_DLL} DESTINATION ${BIN_FOLDER}) file(COPY ${OPENCV_DLL} DESTINATION ${BIN_FOLDER}) - file(COPY ${OPENCV3PTY_DLL} DESTINATION ${BIN_FOLDER}) + file(COPY ${CAFFE_3RD_PARTY_DLL} DESTINATION ${BIN_FOLDER}) + file(COPY ${GLUT_DLL} DESTINATION ${BIN_FOLDER}) + file(COPY ${SPINNAKER_DLL} DESTINATION ${BIN_FOLDER}) endif (BUILD_BIN_FOLDER) endif (WIN32) diff --git a/doc/modules/python_module.md b/doc/modules/python_module.md index 94eddf90..8252cdc3 100644 --- a/doc/modules/python_module.md +++ b/doc/modules/python_module.md @@ -1,11 +1,13 @@ -OpenPose Python Module +OpenPose Python Module and Demo ============================================= ## Contents 1. [Introduction](#introduction) -2. [Installation](#installation) -3. [Compatibility](#compatibility) +2. [Compatibility](#compatibility) +3. [Installation](#installation) 4. [Testing](#testing) +5. [Exporting Python OpenPose](#exporting-python-openpose) + ## Introduction @@ -13,12 +15,15 @@ This experimental module exposes a Python API for OpenPose. This allows you to c At present the Python API only supports body pose. Hands and Face will be added in the future. -## Installation -Check [doc/installation.md#python-module](./installation.md#python-module) for installation steps. -To simply test the OpenPose API in your project without installation, ensure that the line `sys.path.append('{OpenPose_path}/python')` is 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. -On an Ubuntu or OSX based system, you may use it globally. Running `sudo make install` will install OpenPose by default into `/usr/local/python`. You can set this into your python path and start using it at any location. +## 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. + + + +## Installation +Check [doc/installation.md#python-module](./installation.md#python-module) for installation steps. The Python API requires Numpy for array management, and OpenCV for image loading. They can be installed via: @@ -27,9 +32,6 @@ pip install numpy pip install opencv-python ``` -## 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. - ## Testing @@ -46,5 +48,8 @@ python 1_extract_pose.py -## Code Sample -See [examples/tutorial_python/1_extract_pose.py](../../../master/examples/tutorial_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_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. diff --git a/examples/tutorial_python/1_extract_pose.py b/examples/tutorial_python/1_extract_pose.py index d4bb4a5e..443a253c 100644 --- a/examples/tutorial_python/1_extract_pose.py +++ b/examples/tutorial_python/1_extract_pose.py @@ -15,7 +15,10 @@ else: sys.path.append('../../python'); # 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 -from openpose import * +try: + from openpose import * +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?') params = dict() params["logging_level"] = 3 params["output_resolution"] = "-1x-1" diff --git a/examples/tutorial_python/2_pose_from_heatmaps.py b/examples/tutorial_python/2_pose_from_heatmaps.py index b8152a3b..e68215c2 100644 --- a/examples/tutorial_python/2_pose_from_heatmaps.py +++ b/examples/tutorial_python/2_pose_from_heatmaps.py @@ -17,7 +17,10 @@ import time dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append('../../python') dir_path + "/../../models/" -from openpose import OpenPose +try: + from openpose import OpenPose +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?') # Params for change defRes = 736 -- GitLab