The OpenCV installing via pip does not include GPU support and will significantly reduce performance. This decreases FPS from around 30FPS to under 2FPS in darknet. To enable the GPU, you must compile opencv with CUDA support.

  1. Create a DEV folder at c:\dev\
  2. Install prereqs
    1. Install Cuda from here
    2. Install Visual Studio from here
    3. Install cmake from here
    4. Download OpenCV from here and extract to dev folder as opencv
    5. Download OpenCV Contrib from here (note that versions should match) and extract to dev folder as opencv-contrib
  3. Run cmake-gui and point the sources folder to c:\dev\opencv\sources
  4. Set the build directory to c:\dev\opencv\build
  5. Adjust the following flags:
    • CMAKE_BUILD_TYPE=RELEASE \
    • CMAKE_INSTALL_PREFIX=/usr/local \
    • WITH_TBB=ON \
    • ENABLE_FAST_MATH=1 \
    • CUDA_FAST_MATH=1 \
    • WITH_CUBLAS=1 \
    • WITH_CUDA=ON \
    • BUILD_opencv_cudacodec=OFF \
    • WITH_CUDNN=ON \
    • OPENCV_DNN_CUDA=ON \
    • CUDA_ARCH_BIN=7.5 \
    • WITH_V4L=ON \
    • WITH_QT=OFF \
    • WITH_OPENGL=ON \
    • WITH_GSTREAMER=ON \
    • OPENCV_GENERATE_PKGCONFIG=ON \
    • OPENCV_PC_FILE_NAME=opencv.pc \
    • OPENCV_ENABLE_NONFREE=ON \
    • OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages \
    • PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
    • OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-4.5.2/modules \
    • INSTALL_PYTHON_EXAMPLES=OFF \
    • INSTALL_C_EXAMPLES=OFF \
    • BUILD_EXAMPLES=OFF
  6. Click Configure and then Generate. When prompted, select the correct version of Visual Studio
  7. From the build directory, open the INSTALL.vcxproj project in Visual Studio
  8. From the Build menu, choose BUILD_ALL (will take an hour or two)
  9. From the Build menu, choose INSTALL (quick)