Ask Your Question

Revision history [back]

I was struggling with this same issue and needed opencv 3.4 with cuda 10.2. Tooks some digging but I believe I figured out what you need to do. It turns out that the opencv cmake search stuff use to deduce the CUDA information is reliant on a number of variables that do not normally get set, mostly because the root path of cuda was all that was needed. I found that if I declare the following setup of environmental variables, I am able to build OpenCV with CUDA enabled without much hassle.

I create the file It's contents follow:

# location of cuda installation     

# location of lib & include paths  (this is what has changed in newer cuda setups)

# location of nvcc




The big ones to make sure are set are CUDA_PATH, CUDA_BIN_PATH, CUDA_LIB_PATH, CUDA_INC_PATH I created the other ones for myself.

If you search through all the cmake files, these variables help cmake properly configure compilation of opencv when available. What I have found is the newer versions of CUDA changed the location of the lib & include paths and that seemed to have broken the search and find parts of cmake. Setting these variables fixes that.

The last thing you should do if compiling opencv with CUDA is declare -DWITH_NVCUVID=OFF unless you are sure you have the prerequisites installed and in the correct places. If this is not set to off, the compilation of cuda fails when it searches for a header associated with this option. I've not used this feature so my process turns it off.

I generally add the '' to /etc/profile.d on my system as adminstrator so these parameters are set for the system.

Hope this helps.