I've just installed OpenCV 3.2 compiling with CUDA support following instruction in http://www.pyimagesearch.com/2016/07/11/compiling-opencv-with-cuda-support/ I just wonder how to check whether my OpenCV is using CUDA and GPU support when running (I use python2.7)
After compiling OpenCV with GPU acceleration support through CUDA and cuDNN, we are ready to install it as if we had downloaded a pre-compiled package. The final step is to create symbolic links to the OpenCV bindings for Python 3, to be used globally.
If OpenCV is compiled with CUDA capability, it will return non-zero for getCudaEnabledDeviceCount function (make sure you have CUDA installed). Another very simple way is to try using a GPU function in OpenCV and use try-catch. If an exception is thrown, you haven't compiled it with CUDA.
OpenCV provides samples on how to work with already implemented methods with GPU support using C++ API. But not so much information comes up when you want to try out Python API, which is also supported.
Starting from OpenCV version 4.2, the DNN module supports NVIDIA GPU usage, which means acceleration of CUDA and cuDNN when running deep learning networks on it. This post will help us learn compiling the OpenCV library with DNN GPU support to speed up the neural network inference.
As you can see in the link you gave, you can always check whether you have installed CUDA
correctly by typing this on python
console.
print(cv2.getBuildInformation())
If you have CUDA support, you will be seen that Use CUDA: YES (version)
in the printed text.
Then you can use opencv cuda commands in cv2.cuda
module.
But as said in that tutorial CUDA
support is not there at present in python. (As these tutorials are on OpenCV python
you will get confused whether this will add CUDA
support for python
. But it will not..)
Furthermore, in a GPU-enabled CUDA environment, there are a number of compile-time optimizations we can make to OpenCV, allowing it to take advantage of the GPU for faster computation (but mainly for C++ applications, not so much for Python, at least at the present time).
But as described in this answer, you can get OpenCL
support on python. As in this document,
Open Computing Language (OpenCL) is an open standard for writing code that runs across heterogeneous platforms including CPUs, GPUs, DSPs and etc.
Edit 1:
Another thing that you can do is, you can write python
wrappers for each GPU
methods in OpenCV C++
and call those methods via python
. I will not recommend that because this will always copy images and other data between GPU
memory and RAM
resulting bad performance. Sometimes this will take more time than CPU
alone.
Another thing that you can do is writing the whole function you need to do using GPU
in C++
and write a python
wrapper for that function. This is much more better than the previous method but you will need to know C++
.
There can be even better ways of doing this..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With