Installing OpenCV w/ GPU in Windows
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 prereqs
- 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_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
- Click Configure and then Generate. When prompted, select the correct version of Visual Studio
- From the build directory, open the INSTALL.vcxproj project in Visual Studio
- From the Build menu, choose BUILD_ALL (will take an hour or two)
- From the Build menu, choose INSTALL (quick)