Daniil-Osokin / lightweight-human-pose-estimation-3d-demo.pytorch

Real-time 3D multi-person pose estimation demo in PyTorch. OpenVINO backend can be used for fast inference on CPU.
Apache License 2.0
653 stars 137 forks source link

[Guide] How to build pose_extractor on Windows #101

Closed HaomingXR closed 5 months ago

HaomingXR commented 7 months ago

Documenting the steps that worked for me, for people who also stumbles upon this in the future

This guide is for Windows only

My Own Environment

OpenCV

You need to first install all the Python requirements

pip install -r requirements.txt

Then when you run

python setup.py build_ext

It should throw an error saying OpenCV is not found.

If so, go to the offical GitHub and download the .exe for Windows. After running it, it should extract a opencv folder to the specified path.

Next, open pose_extractor/CMakeLists.txt and add a line above the find_package line for OpenCV, pointing to the build folder that contains the OpenCVConfig.cmake file. Now it should for example look like this:

set(OpenCV_DIR "C:/Program Files/opencv/build")
find_package(OpenCV 4 REQUIRED)

The build should then finish correctly.

Python Path

Now comes the part that caused the most problems for many people.

You can remove the try-except block to see the exact errors thrown when trying to load the fast pose_extractor

When you run the script, it should throw an error saying that the module was not found. This is because the built .pyd file is not found in the path. And since I'm launching the Python script directly, I cannot do

export PYTHONPATH=pose_extractor/build/:$PYTHONPATH

To solve this, open modules/parse_poses.py, and add the following:

import sys
sys.path.append('pose_extractor/build')

This does basically the same thing, adding the build folder to the Python path.

You would think it could run correctly now. But for me, it now throws a different error, saying something like DLL not found, meaning the .pyd file is missing its dependency.

To solve this, open modules/parse_poses.py again, and add a line that points to the OpenCV .dlls:

import os
os.add_dll_directory(r'C:\Program Files\opencv\build\x64\vc16\bin')

The above 4 lines should all be above the from pose_extractor import extract_poses line

Now, it should finally run the fast pose_extractor correctly on Windows~

Daniil-Osokin commented 5 months ago

Thanks for providing the details of your experience! :shipit: