OpenCV with CUDA on Windows: GPU Acceleration

Enable GPU acceleration for OpenCV on Windows 11/10. Understand CUDA/cuDNN compatibility, where to get CUDA-enabled builds, how to verify acceleration, and how to avoid common pitfalls.

  • Hardware: NVIDIA GPU with recent driver
  • Software: Matching CUDA Toolkit and optional cuDNN
  • Note: The official Windows installer is typically CPU-only; CUDA requires a CUDA-enabled build

TL;DR — GPU quick steps

  1. Check driver and select a compatible CUDA Toolkit version.
  2. Get a CUDA-enabled OpenCV build (prebuilt or build from source).
  3. Install cuDNN if your modules require it.
  4. Verify that OpenCV detects your CUDA device.

Need Python or C++ specifics? See Python and C++ pages.

Compatibility: drivers, CUDA Toolkit, and cuDNN

  • Use an NVIDIA driver version that supports your chosen CUDA Toolkit.
  • Align the CUDA Toolkit with the OpenCV CUDA build you plan to use.
  • Install cuDNN only if your workflows require deep neural network modules.

Ways to obtain CUDA-enabled OpenCV

  • Prebuilt community builds: convenient but verify trust and version alignment.
  • Build from source: maximum control over CUDA flags and dependencies; ensure MSVC, CMake, CUDA, and OpenCV sources align.
  • Package managers: some provide CUDA variants; check availability and compatibility on Windows.

Verification checklist

  • Confirm that the build reports CUDA support enabled.
  • Ensure at least one CUDA device is detected on your system.
  • Run a simple GPU-accelerated operation and compare timings with CPU.

Common pitfalls

  • Version mismatch: driver, CUDA Toolkit, and OpenCV build must be compatible.
  • Missing DLLs: ensure CUDA/cuDNN runtime libraries are discoverable at run time.
  • Multiple toolchains: avoid mixing MSVC versions across dependencies.
  • x86 vs x64: use x64 throughout the toolchain and libraries.

CUDA / GPU FAQ on Windows

Does the official Windows installer include CUDA?
Typically no. The official installer targets CPU builds. For GPU, use a CUDA-enabled build of OpenCV (prebuilt from a trusted source or build from source).
Which CUDA Toolkit version should I install?
Pick a version supported by your NVIDIA driver and by the CUDA-enabled OpenCV build you plan to use. Keep versions aligned.
Do I need cuDNN?
Only if you plan to use deep neural network modules that benefit from cuDNN. Otherwise, it is optional.
How do I verify that CUDA works?
Check that your OpenCV build reports CUDA enabled and that at least one GPU device is detected. Then benchmark a GPU operation against CPU.

Related pages