openpose icon indicating copy to clipboard operation
openpose copied to clipboard

Import openpose in different script Python API on Windows

Open vincenzomarotta opened this issue 1 year ago • 2 comments

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 'openpose_importer' has no attribute 'WrapperPython'

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

vincenzomarotta avatar May 18 '24 11:05 vincenzomarotta

Getting the same problem ^

kylefraze avatar Nov 14 '24 00:11 kylefraze

Getting the same problem ^

Unfortunately I did not manage to solve it, I just used it in my main file

vincenzomarotta avatar Nov 15 '24 16:11 vincenzomarotta