Installing OpenCV w/ GPU in Windows: Difference between revisions

No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:


# Create a DEV folder at c:\dev\
# Create a DEV folder at c:\dev\
# Install Cuda from [https://developer.nvidia.com/cuda-downloads here]
# Install prereqs
# Install Visual Studio from [https://visualstudio.microsoft.com/downloads/ here]
## Install Cuda from [https://developer.nvidia.com/cuda-downloads here]
# Install cmake
## Install Visual Studio from [https://visualstudio.microsoft.com/downloads/ here]
# Download OpenCV from [https://opencv.org/releases/ here] and extract to dev folder as opencv
## Install cmake from [https://cmake.org/download/ here]
# Download OpenCV Contrib from [https://github.com/opencv/opencv_contrib/releases here] (note that versions should match) and extract to dev folder as opencv-contrib
## Download OpenCV from [https://opencv.org/releases/ here] and extract to dev folder as opencv
## Download OpenCV Contrib from [https://github.com/opencv/opencv_contrib/releases 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
# Run cmake-gui and point the sources folder to c:\dev\opencv\sources
# Set the build directory to c:\dev\opencv\build
# Set the build directory to c:\dev\opencv\build
Line 36: Line 37:
# 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)

Latest revision as of 13:22, 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 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)