# cv2.error: OpenCV(4.7.0) /modules/dnn/src/dnn.cpp: error: (-2:Unspecified error) DNN module was not built with CUDA backend; switched to CPU

- **ID:** `opencv/dnn-cuda-backend-missing`
- **Domain:** opencv
- **Category:** config_error
- **Error Code:** `-2`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

The OpenCV installation does not include CUDA support for DNN, so GPU acceleration is unavailable and falls back to CPU.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.0 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

1. **Rebuild OpenCV from source with CUDA enabled: set -DWITH_CUDA=ON and -DWITH_CUDNN=ON in CMake, and ensure CUDA toolkit and cuDNN are installed.** (80% success)
   ```
   Rebuild OpenCV from source with CUDA enabled: set -DWITH_CUDA=ON and -DWITH_CUDNN=ON in CMake, and ensure CUDA toolkit and cuDNN are installed.
   ```
2. **Use a pre-built OpenCV package that includes CUDA support, such as from conda-forge (opencv with cuda variant) or NVIDIA's official Docker images.** (70% success)
   ```
   Use a pre-built OpenCV package that includes CUDA support, such as from conda-forge (opencv with cuda variant) or NVIDIA's official Docker images.
   ```

## Dead Ends

- **Set environment variable OPENCV_DNN_CUDA=1** — This environment variable does not exist; CUDA support must be compiled into OpenCV. (95% fail)
- **Install CUDA toolkit after OpenCV installation** — CUDA toolkit must be present at build time; installing it after does not add CUDA support to an existing OpenCV build. (85% fail)
- **Use cv2.dnn.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) to force CUDA** — If the DNN module was not built with CUDA, this call will throw the same error; it does not enable CUDA at runtime. (90% fail)
