Skip to content

Windows 安装支持 GPU 的 opencv-python

确保 Python 是 64 位

sh
python -c "import sys,platform; print(sys.version); print(platform.architecture())"

安装 CUDA Toolkit + cuDNN

参考:Windows 安装 CUDA Toolkit + cuDNN

卸载 CPU build 版本的 opencv-python

sh
pip uninstall -y opencv-python opencv-contrib-python
# pip uninstall -y opencv-python-headless opencv-contrib-python-headless
# pip uninstall -y opencv-python-rolling opencv_contrib_python_rolling

安装 CUDA 版本的 opencv-python

访问 cudawarped/opencv-python-cuda-wheels

cuda 12.9 + cudnn 9.10.2

cuda 12.2 + cudnn 8.9.3

下载并安装:

sh
# cd <下载目录>
pip install opencv_contrib_python-4.12.0.88-cp37-abi3-win_amd64.whl

检查是否安装成功

检查 OpenCV 版本信息:

sh
python -c "import cv2; print(cv2.getBuildInformation())"

检查是否支持 CUDA:

sh
python -c "import cv2; print('CUDA devices:', cv2.cuda.getCudaEnabledDeviceCount())"

输出形如:

sh
CUDA devices: 1