CUDA guide

OpenCV CUDA GPU acceleration on Windows — build & setup guide

Enable CUDA GPU acceleration for OpenCV on Windows. Covers requirements, CUDA Toolkit setup, CMake build flags, CUDA_ARCH_BIN values and verifying GPU is active.

OpenCV pip wheels do NOT include CUDA support. To use GPU acceleration you must build OpenCV from source with CUDA enabled, or use the pre-built CUDA build from opencv.org.

CUDA + OpenCV compatibility on Windows

ComponentRequired versionNotes
GPUNVIDIA only (CUDA)GTX 900+ or RTX series recommended
CUDA Toolkit11.8, 12.0, 12.3+Match with cuDNN version
cuDNN8.x or 9.xRequired for DNN module GPU support
NVIDIA driver520+ (for CUDA 12)Latest Game Ready or Studio driver
Visual Studio2019 or 2022Required to compile CUDA code

Verify CUDA is available before building

cmd.exe
# Check NVIDIA driver and CUDA version:
C:\> nvidia-smi
Driver Version: 546.01 | CUDA Version: 12.3
# Check CUDA Toolkit is installed:
C:\> nvcc --version
Cuda compilation tools, release 12.3, V12.3.107
If nvcc is not found, download CUDA Toolkit from developer.nvidia.com/cuda-downloads.

Build OpenCV with CUDA on Windows

  • 1

    Install prerequisites

    Install: Visual Studio 2022, CMake, CUDA Toolkit, cuDNN. Install Python if you want Python bindings. Clone or download OpenCV source and opencv_contrib source.

  • 2

    Configure with CMake

    PowerShell — Developer
    PS> cmake -B build -S . `
    -DWITH_CUDA=ON `
    -DCUDA_ARCH_BIN="8.6" `
    # 8.6 = RTX 30xx, 8.9 = RTX 40xx, 7.5 = RTX 20xx
    -DWITH_CUDNN=ON `
    -DOPENCV_DNN_CUDA=ON `
    -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules `
    -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF
  • 3

    Build and install

    PowerShell
    PS> cmake --build build --config Release --parallel 8
    # Takes 30-90 minutes depending on hardware
    PS> cmake --install build --config Release
  • 4

    Verify CUDA is active

    Python
    import cv2
    print(cv2.cuda.getCudaEnabledDeviceCount())
    1
    # 0 means CUDA not available or build failed
    print(cv2.cuda.printCudaDeviceInfo(0))
    Device 0: "NVIDIA GeForce RTX 3080"

CUDA questions

cv2.cuda.getCudaEnabledDeviceCount() returns 0
Either the OpenCV build was not compiled with CUDA, or your GPU driver/CUDA version mismatch. Run cv2.getBuildInformation() and check if CUDA shows YES. If not, the pip-installed OpenCV has no CUDA — you must build from source.
Which CUDA_ARCH_BIN value should I use?
Use the compute capability of your GPU: RTX 40xx = 8.9, RTX 30xx = 8.6, RTX 20xx = 7.5, GTX 16xx = 7.5, GTX 10xx = 6.1. You can build for multiple architectures: -DCUDA_ARCH_BIN="7.5;8.6;8.9".
Can AMD GPUs use CUDA acceleration?
No. CUDA is NVIDIA-only. AMD GPUs can use OpenCL acceleration in OpenCV: build with -DWITH_OPENCL=ON. Performance is generally lower than CUDA. There is also experimental ROCm support on Linux.

Need to build OpenCV from source?

Full CMake build guide for Windows.

CMake build guide