Build openpose with/without GPU support for macOS (Catalina 10.15.6)

Alok Gandhi
6 min readAug 14, 2020

--

OpenPose represents the first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints (in total 135 keypoints) on single images.

Building openpose for macOS can be quite challenging given the sheer number of dependencies and build steps. Although the official docs are comprehensive and cover almost everything, it would still be nice to have a step by step procedure that covers all issues and gotchas. With this objective, the following is an easy-to-follow and clean build process.

Before you begin

Part A: Get the source code and dependencies

Part B — Build caffe

Part C — Build examples and shared libs

Run examples and test

Before you Begin

Prerequisites

You should have the following on your mac

Step order is important

For a successful build, please follow all the steps in exactly the same order as described below. If you miss or reorder any of the steps this might not work. I have spent a considerable amount of time in painfully figuring this out after significant trial and error.

Building without GPU support

  • If you do not have a GPU on your machine, you can still build openpose without GPU support by making the following changes:
  • In Step 3 below, set GPU_MODE = CPU_ONLY
  • Completely skip Step 5 for applying a patch for GPU build

A word about build environment (hardware and software)

Do note that this has been tested on a Mac Book Pro with macOS (Catalina 10.15.6). Other MacBooks / macOS versions are not tested but in all probability, this should still work. Below are the specs on which the build was tested

Part A — Get the source code and dependencies

First we will pull the source code cloning the official openpose github repo and also install all the required dependencies.

Step 1: Clone repository

Create a new folder where you want to build openpose

mkdir openpose_build

cd openpose_build

git clone --recursive git@github.com:CMU-Perceptual-Computing-Lab/openpose.git

cd openpose

Let’s call this cloned repo folder “<root path>” for the rest of this doc.

Note: The ` — recusive` flag, it makes sure that all the sub-modules (caffe, pybind, etc. are cloned as well)

Step 2: Install dependencies

<root path>/scripts/osx/install_deps.sh

Note(optional): In addition to adding libs from brew, install_deps.sh also adds some python packages. If you see an error in installing opencv-python, edit install_deps.sh change the line

sudo pip install opencv-python

to

sudo pip install opencv-contrib-python

and run again

Note(optional): Just in case you do not have brew on your machine, you can install brew by running

<root path>/scripts/osx/install_brew.sh

or you can install from the official source

Part B — Build caffe

Next, we will build Caffe which is a major dependency of openpose lib. The CMU Perceptual Lab team has worked on a fork of caffe and included this as a submodule in the openpose git repo. Per the official docs -

Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by Berkeley AI Research (BAIR)/The Berkeley Vision and Learning Center (BVLC) and community contributors.

Step 3: Config build settings for caffe

Now we will config our build settings for building caffe libs

  • Open CMake GUI
cmake-gui
  • Set the project and build paths as below
Where is the code = <root path>
Where to build the binaries = <root path>/build
  • Click on Configure
  • Click Yes for creating the build folder (in case you have not already created). This will create the initial config and download all the remaining necessary files.
  • In the next dialog, do not change any settings. Defaults are good — Generator is Unix Makefiles and Use default native compilers. Click Done
  • After the download finishes, build settings will be displayed with some items colored in red. Make the following changes to the build settings in the UI
[√] BUILD_CAFFE
[ ] BUILD_EXAMPLES
[ ] BUILD_SHARED_LIBS
Caffe_INCLUDE_DIRS = <root path>/build/caffe/include
GPU_MODE = OPENCL
  • Leave the rest of the settings to default
  • Click Configure a few times until all the red color items are gone. The log will show: Configuring done
  • Click Generate. The log will show: Generating done
  • We are ready to build caffe now

Note: Keep the CMake GUI open, we will use this for the further build process.

Step 4: Manually generate headers

Generate the missing caffe.pb.h header file for proto

protoc <root path>/3rdparty/caffe/src/caffe/proto/caffe.proto --cpp_out=.

mkdir <root path>/3rdparty/caffe/include/caffe/proto

mv <root path>/3rdparty/caffe/src/caffe/proto/caffe.pb.h <root path>/3rdparty/caffe/include/caffe/proto

See this issue for more details.

Step 5: Apply patch to caffe for opencl support (required for GPU mode only)

This fixes: Fatal error: ‘opencv2/highgui/highgui.hpp’ file not found (details here)

cd <root path>/3rdparty/caffe

git apply ../../scripts/osx/mac_opencl_patch.txt

Step 6: Run Caffe Build

cd <root path>/build

make -j`sysctl -n hw.logicalcpu`

Wait for the build to finish. Hopefully, without errors, warnings are ok. You should see the following in the terminal

Part C — Build examples and shared libs

Step 7: Config build setting for examples and shared libs

Make the following changes to the build settings in the already open CMake GUI app from Step 3 above

[ ] BUILD_CAFFE
[√] BUILD_EXAMPLES
[√] BUILD_SHARED_LIBS
Caffe_LIBS = <root path>/build/caffe/lib/libcaffe.dylib

Leave the rest of the settings to default

  • Click Configure again. The log will show: Configuring done
  • Click Generate. The log will show: Generating done
  • We are ready to finally build openpose libs and executable binaries now

Step 8: Finally build examples and shared libs

cd <root path>/build

make -j`sysctl -n hw.logicalcpu`

Hopefully, this should finally build everything

Run examples and test

Detailed instructions for running demos can be found here on the official docs.

  • Process Video
<root path>/build/examples/openpose/openpose.bin --video examples/media/video.avi
  • Running openpose on live camera feed (with GPU)
<root path>/build/examples/openpose/openpose.bin --num_gpu 1 --num_gpu_start 2

Enjoy!

--

--