CMU-Perceptual-Computing-Lab / openpose

OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation
https://cmu-perceptual-computing-lab.github.io/openpose
Other
30.33k stars 7.79k forks source link

Import openpose in different script Python API on Windows #2296

Open vincenzomarotta opened 1 month ago

vincenzomarotta commented 1 month ago

Windows 11 / Latest Openpose / Python 3.9

Hello, I built openpose correctly on my Windows machine, everything works, imports work perfectly too.

I wanted to create a python script where I wanted to put openpose import and in my main file I wanted to execute it, Is there any way to import pyopenpose in a simpler way?

For example: oenpose_importer.py

import os
import cv2
import sys
from sys import platform
import argparse
import time

# Import Openpose (Windows/Ubuntu/OSX)
#dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path = "path_to/openpose
try:
    # Windows Import
    if platform == "win32":
        # Change these variables to point to the correct folder (Release/x64 etc.)
        sys.path.append(dir_path + '/build/python/openpose/Release');
        os.add_dll_directory(dir_path + '/build/x64/Release')
        os.add_dll_directory(dir_path + '/build/bin')
        #print("Openpose imported correctly")
        import pyopenpose as op
    else:
        # 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')
        from openpose import pyopenpose as op
except ImportError as e:
    print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?')
    raise e

in my main.py

import os
import cv2
import sys
from sys import platform
import argparse
import time
import openpose_importer as op
# CODE HERE

Right now I'm getting the error: _module 'openposeimporter' has no attribute 'WrapperPython'

Is there any way to achive what I'm trying to do?