Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Accessing Functions with Python Ctypes on .so Files

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!