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.
- Create a DEV folder at c:\dev\
- Install cmake
- Download OpenCV from here and extract to dev folder as opencv
- Download OpenCV Contrib from here (note that versions should match) and extract to dev folder as opencv-contrib
- Run cmake-gui and point the sources folder to c:\dev\opencv\sources
- Set the build directory to c:\dev\opencv\build
- Adjust the following flags:
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_TBB=ON \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=1 \ -D WITH_CUBLAS=1 \ -D WITH_CUDA=ON \ -D BUILD_opencv_cudacodec=OFF \ -D WITH_CUDNN=ON \ -D OPENCV_DNN_CUDA=ON \ -D CUDA_ARCH_BIN=7.5 \ -D WITH_V4L=ON \ -D WITH_QT=OFF \ -D WITH_OPENGL=ON \ -D WITH_GSTREAMER=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_PC_FILE_NAME=opencv.pc \ -D OPENCV_ENABLE_NONFREE=ON \ -D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages \ -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \ -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-4.5.2/modules \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D INSTALL_C_EXAMPLES=OFF \ -D BUILD_EXAMPLES=OFF ..