1
votes

I have a question regarding the CUDA modules in OpenCV 3. Formerly in OpenCV 2 there was the opencv_gpu module and there was always a opencv2/gpu/gpu.hpp file in the include folder. It would be moved there during install whether OpenCV was built with CUDA or without. In the latter case however, CUDA functions would not be usable later in the code, which could be checked by invoking cv::gpu::getCudaEnabledDeviceCount() which would then always return 0. This way a program that used CUDA could be compiled with versions of OpenCV that were built with CUDA, as well as with ones built without CUDA.

In Opencv 3.0 the CUDA functions have been moved to the modules cudaarithm, cudaimgproc, cudafilters, cudawarping and so on. They are only available if you add the opencv contrib repository.

Now, I was creating a program that uses cuda. Then I realized, that when building and installing OpenCV without CUDA, meaining the machine does not support CUDA and the NVIDIA cuda toolkit is not installed, the header files for the CUDA modules are not copied into the include folder when installing. This way the program doesn't compile. How do you compile a program using the OpenCV CUDA modules with a build that was built without CUDA in OpenCV 3?

2

2 Answers

1
votes

Previous Version OpenCV upto 2.3 default build was with CUDA from that onwards if you want to run Opencv with cuda support you have build OpenCV from source with CUDA Check This Guide. You must have a CUDA enabled GPU to run Opencv with CUDA. NVIDIA CUDA enabled GPU List

0
votes

Ok, at least for OpenCV 3.1 it appears not to be a problem. The cuda modules have also been moved back to the main repository.

It is necessary to have a version of OpenCV compiled with CUDA. That can be done also on a machine without an Nvidia GPU. The Nvidia CUDA toolkit has to be installed (just ignore the warning message about the GPU). The graphics driver, however, is not required. This way compiling OpenCV with CUDA should not be a problem also on a machine that is not CUDA-enabled.

In your project you can then just include the cudaarithm etc. modules and perform the check if any CUDA devices are available at runtime, just like before.