OpenCV have supported CUDA for a long time. Though it also provides Python API for most of its functions, it has no Python API for its CUDA functions written in C++, in its early versions.
Therefore, if you are requested to wrap OpenCV CUDA function into Python API for those early OpenCV versions, then here is the right place.
Otherwise, I recommend you to keep track OpenCV 4.0 Version, they're working on Python API for CUDA function now on this branch.
What the example doing here is to wrap the following cuda function:
void cv::cuda::remap( InputArray src,
OutputArray dst,
InputArray xmap,
InputArray ymap,
int interpolation,
int borderMode = BORDER_CONSTANT,
Scalar borderValue = Scalar(),
Stream & stream = Stream::Null()
)
If you would like to use this .so
file, feel free to get it. It should be correct if your src image is of CV_8U3C. Also, feel free to open an issue if you have any doubts.
-
Cython installation
-
CUDA installation(it is a must if you want to wrap CUDA function)
-
OpenCV and OpenCV contribute installation
-
Numpy installation(actually when you install OpenCV, you should have installed Numpy first)
Python(Numpy)--> C++(OpenCV Mat/others)--> Call C++ function--> Return C++ Data Structure--
| |
--------------------------------------------------------------------------------------
First, to build the example,
-
Check the configuration in
setup.py
, what really matters is the library paths of OpenCV and Numpy. -
Run
python setup.py build_ext --inplace
. If there is anything wrong here, go and check your path. Otherwise, you may need to figure out if there is anything wrong with the pre-request dependency. -
After that, you will get a
.so
file, which contains your desired cuda function. It means that your dependency is ready. If you see warning like the following, it is alright:cc1plus: warning: command line option ‘**-Wstrict-prototypes**’ is valid for C/ObjC but not for C++.
warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
-
Then, you need to copy or move the .so file to the place where your python interpreter can find it.
-
Finally, you can simply write
import GpuWrapper
, the name of the.so
file, then you can use the cuda function in your python code directly.
Second, to write your own functions,
- Read the documentation of OpenCV. Pay attention to input/output data Structure
- Write the dependent data structure/ class/ function in the
.pxd
file. - Write your own logic in
.pyx
file. - Repeat the procedure in first step.
pyopencv_converter.cpp
is the code that convert , which is copied from OpenCV. It deals with the convertion from Python(Numpy data structure) to C++(OpenCV Mat data structure). So, you don't really need to care about this.