Last active
March 4, 2021 23:51
-
-
Save nanguoyu/9b1369c140907c871b7c91713b16bcb8 to your computer and use it in GitHub Desktop.
Install OpenCV with GPU support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install qt5-default | |
sudo apt-get install opencl-headers | |
sudo pip install pylint | |
# Install minimal prerequisites (Ubuntu 18.04 as reference) | |
sudo apt update && sudo apt install -y cmake g++ wget unzip | |
# Download and unpack sources | |
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip | |
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/master.zip | |
unzip opencv.zip | |
unzip opencv_contrib.zip | |
# Create build directory and switch into it | |
mkdir opencv-master/build && cd build | |
# Note you should chaneg CUDA_ARCH_BIN=7.0 according to your GPU | |
cmake \ | |
-D CMAKE_BUILD_TYPE=RELEASE \ | |
-D CMAKE_INSTALL_PREFIX=/usr/local \ | |
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-master/modules/ \ | |
-D CUDA_CUDA_LIBRARY=/usr/local/cuda-11.0/lib64/stubs/libcuda.so \ | |
-D CUDA_ARCH_BIN=7.0 \ | |
-D CUDA_ARCH_PTX="" \ | |
-D WITH_CUDA=ON \ | |
-D WITH_TBB=ON \ | |
-D BUILD_PYTHON_SUPPORT=ON \ | |
-D BUILD_NEW_PYTHON_SUPPORT=ON \ | |
-D BUILD_OPENCV_PYTHON3=ON \ | |
-D PYTHON3_EXECUTABLE=/usr/lib/miniconda3/bin/python3.8 \ | |
-D PYTHON3_PACKAGES_PATH=/usr/lib/miniconda3/lib/python3.8/site-packages \ | |
-D WITH_V4L=ON \ | |
-D INSTALL_C_EXAMPLES=ON \ | |
-D INSTALL_PYTHON_EXAMPLES=ON \ | |
-D BUILD_EXAMPLES=ON \ | |
-D WITH_QT=ON \ | |
-D WITH_OPENGL=ON \ | |
-D ENABLE_FAST_MATH=1 \ | |
-D CUDA_FAST_MATH=1 \ | |
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.0 \ | |
-D CMAKE_LIBRARY_PATH=/usr/local/cuda-11.0/lib64/stubs \ | |
-D WITH_CUBLAS=ON \ | |
-D WITH_NVCUVID=ON \ | |
-D BUILD_opencv_cudacodec=ON .. | |
cmake --build . | |
sudo make install | |
sudo mv /usr/local/include/opencv4/opencv2 /usr/local/include/opencv2 | |
cp lib/python3/cv2.cpython-38-x86_64-linux-gnu.so cv2.so | |
mv cv2.so /usr/lib/miniconda3/lib/python3.8/site-packages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment