Site icon Machine Learning Projects

How to build OpenCV with Cuda and cuDNN support in Windows – 2023

Machine Learning Projects

Hey guys, in this blog we will see how we can build OpenCV with Cuda and cuDNN support in Windows. This process can be very tricky and tedious if doing it for the very first time. So without any further due, let’s do it.

Step 0 – Uninstall Python and Anaconda.

Step 1 – Download Cmake

Step 2 – Download Visual Studio


Step 3 – Download OpenCV

Step 4 – Download opencv-contrib

Step 5 – Extract files.

Step 6 – Run Cmake GUI.

Now search the following

Step 7 – Build OpenCV with CUDA

Step 8 – Check OpenCV Installation.

import cv2
import numpy as np
import cv2 as cv
import time

npTmp = np.random.random((1024, 1024)).astype(np.float32)

npMat1 = np.stack([npTmp,npTmp],axis=2)
npMat2 = npMat1

cuMat1 = cv.cuda_GpuMat()
cuMat2 = cv.cuda_GpuMat()
start_time = time.time()
cv.cuda.gemm(cuMat1, cuMat2,1,None,0,None,1)
print("CUDA --- %s seconds ---" % (time.time() - start_time))
start_time = time.time()

print("CPU --- %s seconds ---" % (time.time() - start_time))

NOTE – If you are facing the below error while running cv2, follow these steps.

And now everything should work like charm!!!

So this is how you will install build OpenCV with CUDA and cuDNN support in windows, thanks for reading it and I hope you are taking something with you after reading this and till the next time ?…

Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projectsFlask projects at

Exit mobile version