Simple GPU access tutorials with OpenCV

asked 2018-09-23 11:28:01 -0600

ebergerly gravatar image

Forgive the broad OpenCV/C++/CUDA/GpuMat question, but does anyone know of a simple tutorial for converting an OpenCV Mat image file to a GpuMat? I've spent the entire weekend looking around, and it appears that the OpenCV GPU functions have changed a lot over time, and tutorials from a few years ago no longer apply.

And compound that with the challenge of setting up CUDA and OpenCV and CMake in a Visual Studio C++ so that you also have GPU support and it's time to tear your hair out.

The closest I've come is this, although this is like the 5th syntax I've tried from different tutorials. It compiles and links okay, but crashes with a "no CUDA support" error:

using namespace cv;
Mat image = imread("d:\\documents\\renders\\img.bmp");
cuda::GpuMat gI; // GPU matrix - for now empty
gI.upload(image); // Upload a data from the system memory to the GPU memory

Thanks much for any help

edit retag flag offensive close merge delete

Comments

The code looks fine. Can you see where the error comes from? What's the output of getCudaEnabledDeviceCount()?

speedymcs gravatar imagespeedymcs ( 2018-09-24 06:45:35 -0600 )edit

Thanks. Not at my machine right now but I have 2 GPU's, a GTX 1070 and 1080ti which presumably are both CUDA enabled. Maybe I need to specify just one device as the target (cudaSetDevice())?

ebergerly gravatar imageebergerly ( 2018-09-24 08:03:42 -0600 )edit

Strange. When I run getCudaEnabledDeviceCount() it returns 0, which means no cuda devices exist. But I'm running cuda code in a separate CUDA app on the gpu's and I can query them fine (cudaGetDeviceProperties()). Also, "cudaGetDeviceCount() returns 2. Anyone know why OpenCV has a problem? thx.

ebergerly gravatar imageebergerly ( 2018-09-24 19:12:23 -0600 )edit

Possibly something went wrong when you compiled OpenCV with CUDA. What's the output of getBuildInformation() in your OpenCV app? There should be a field Use Cuda, does it say YES or NO?

speedymcs gravatar imagespeedymcs ( 2018-09-27 03:26:37 -0600 )edit