Ask Your Question
0

Accessing Functions with Python Ctypes on .so Files

asked 2017-02-13 01:56:08 -0600

ostrumvulpes gravatar image

Hello everybody,

I am trying to use Python's ctypes module to directly access functions that do not have Python bindings in OpenCV. More specifically, I want to access cv::cuda::warpPerspective from the module cudawarping.

I was hoping that with the following Python code, I could create a handle to the CUDA-accelerated warpPerspective function:

_CUDAWARPING = ctypes.cdll.LoadLibrary(os.path.join(_OPENCV_SO_DIR, "libopencv_cudawarping.so"))
_func = _CUDAWARPING.warpPerspective

However, after encountering a NameError and diving into libopencv_cudawarping.so, I discovered that there is no particular single warpPerspective function, and everything seems a bit mangled in a way I don't quite understand:

                 U nppiWarpPerspectiveBack_8u_C1R
                 U nppiWarpPerspectiveBack_8u_C3R
                 U nppiWarpPerspectiveBack_8u_C4R
                 U nppSetStream
0000000000106260 T ownFeaturesToIdx
0000000000191740 T ownGetFeature
0000000000191380 T ownGetMaskFeatures
0000000002c06fc0 D own_ipps_sCos_E7_ctab
00000000001c66a0 T own_ipps_sCos_E7EPnnn

I have two questions:

  1. I wanted to know why it isn't as straightforward as I thought it was to access the functions in the original C++ files through ctypes.

  2. My next bet is to write some of my own C++ source code as a wrapper for the functions I do want to call, and then use Python's ctypes to wrap that instead. Does this seem like a feasible approach?

Thanks for helping me understand this better!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-02-13 02:00:34 -0600

berak gravatar image

forget that idea.

opencv is a c++ library, ctypes won't find anything useful (name-mangling)

edit flag offensive delete link more

Comments

So I'm better off writing my own C++ code to call any OpenCV functions I need that don't have Python bindings, and then referencing my own code with ctypes?

ostrumvulpes gravatar imageostrumvulpes ( 2017-02-13 02:02:26 -0600 )edit

again, ctypes won't be helpful at all here.

yes, you'll have to write your own python wrappers for GpuMat and the resp. function calls

berak gravatar imageberak ( 2017-02-13 02:07:19 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-13 01:56:08 -0600

Seen: 789 times

Last updated: Feb 13 '17