Installing OpenCV w/ GPU in Windows: Difference between revisions

No edit summary
No edit summary
Line 36: Line 36:
# Click Configure and then Generate. When prompted, select the correct version of Visual Studio
# 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 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)

Revision as of 13:18, 21 September 2021

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 Cuda from here
  3. Install Visual Studio from here
  4. Install cmake from here
  5. Download OpenCV from here and extract to dev folder as opencv
  6. Download OpenCV Contrib from here (note that versions should match) and extract to dev folder as opencv-contrib
  7. Run cmake-gui and point the sources folder to c:\dev\opencv\sources
  8. Set the build directory to c:\dev\opencv\build
  9. 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
  10. Click Configure and then Generate. When prompted, select the correct version of Visual Studio
  11. From the build directory, open the INSTALL.vcxproj project in Visual Studio
  12. From the Build menu, choose BUILD_ALL (will take an hour or two)
  13. From the Build menu, choose INSTALL (quick)