I am trying to cimport cv2 in Cython Code.
cimport cv2
I have installed the Python OpenCV module and the Cython wrapper for OpenCV, but I'm unsure how to cimport the cv2 module in my Cython code.
To get the best performance, if not cimport, how should the cv2 C++ code be imported and run directly using Cython?
This is the error that I am getting
Error compiling Cython file:
'opencv/cv.pxd' not found
No you can't cimport cv
because the Python binding of OpenCV isn't written in Cython.
If you really wanted you could re-wrap the C++ OpenCV interface in Cython. I don't recommend this because it's a lot of work and you'd probably lose their nice use of Numpy arrays in place of the C++ cv::Mat
.
To be honest this calling OpenCV from Cython is not likely to be worthwhile. Most OpenCV functions operate on whole images at a time. Therefore the function call overhead is likely fairly small compared to the actual cost of the function. What Cython is good at it speeding up operations where you're indexing a lot of individual pixels, and you can definitely mix that kind of Cython code with calls to OpenCV.
But just import
OpenCV normally.