opencv configuration_error ai_generated true

cv2.error: OpenCV was built without CUDA support; cv2.cuda is not available

ID: opencv/cuda-module-not-compiled

Also available as: JSON · Markdown
82%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4 active

Root Cause

OpenCV cv2.cuda module is not available because the installed build was compiled without CUDA support.

generic

Workarounds

  1. 90% success Build OpenCV from source with CUDA enabled
    cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN=8.6 -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..

    Sources: https://docs.opencv.org/4.x/d0/d05/tutorial_dnn_googlenet.html

  2. 85% success Use pre-built CUDA-enabled OpenCV packages
    conda install -c conda-forge opencv  # some conda builds include CUDA
  3. 88% success Use CPU equivalents of CUDA functions for portability
    # Instead of cv2.cuda.GpuMat, use regular cv2.Mat operations which run on CPU

Dead Ends

Common approaches that don't work:

  1. pip install opencv-contrib-python expecting CUDA support 90% fail

    PyPI wheels are not built with CUDA. Even opencv-contrib-python from pip has no CUDA.

  2. Install CUDA toolkit after opencv-python hoping it activates CUDA 88% fail

    OpenCV must be compiled with CUDA at build time. Installing CUDA later has no effect on existing OpenCV.