Forked from p3jitnath/opencv-4.2.0-cuda-10.1-Ubuntu-20.04.md
Created
November 30, 2020 10:26
-
-
Save Starslayerx/b411e311a32dc9a03d92d1f7d7e66cc3 to your computer and use it in GitHub Desktop.
Revisions
-
p3jitnath revised this gist
May 15, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -186,7 +186,7 @@ int main() { std::clock_t begin = std::clock(); try { cv::String filename = "image.png"; // Enter your image path cv::Mat srcHost = cv::imread(filename, cv::IMREAD_GRAYSCALE); for(int i=0; i<1000; i++) { -
p3jitnath revised this gist
May 15, 2020 . 2 changed files with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -90,6 +90,7 @@ We will now proceed with the installation (see the Qt flag that is disabled to d -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D WITH_TBB=ON \ -D WITH_CUDA=ON \ -D BUILD_opencv_cudacodec=OFF \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=1 \ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -51,6 +51,7 @@ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D WITH_TBB=ON \ -D WITH_CUDA=ON \ -D BUILD_opencv_cudacodec=OFF \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=1 \ -
p3jitnath revised this gist
May 14, 2020 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -87,7 +87,4 @@ sudo nano /usr/local/lib/python3.8/dist-packages/cv2/config-3.8.py PYTHON_EXTENSIONS_PATHS = [ os.path.join('/usr/local/lib/python3.8/dist-packages/cv2', 'python-3.8') ] + PYTHON_EXTENSIONS_PATHS ``` -
p3jitnath revised this gist
May 14, 2020 . 2 changed files with 94 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -69,7 +69,7 @@ We will now proceed with the installation (see the Qt flag that is disabled to d $ unzip opencv.zip $ unzip opencv_contrib.zip $ echo "Create a virtual environment for the python binding module" $ sudo pip install virtualenv virtualenvwrapper $ sudo rm -rf ~/.cache/pip $ echo "Edit ~/.bashrc" This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,93 @@ sudo apt update sudo apt upgrade sudo apt install build-essential cmake pkg-config unzip yasm git checkinstall sudo apt install libjpeg-dev libpng-dev libtiff-dev sudo apt install libavcodec-dev libavformat-dev libswscale-dev libavresample-dev sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev sudo apt install libxvidcore-dev x264 libx264-dev libfaac-dev libmp3lame-dev libtheora-dev sudo apt install libfaac-dev libmp3lame-dev libvorbis-dev sudo apt install libopencore-amrnb-dev libopencore-amrwb-dev sudo apt-get install libdc1394-22 libdc1394-22-dev libxine2-dev libv4l-dev v4l-utils cd /usr/include/linux sudo ln -s -f ../libv4l1-videodev.h videodev.h cd ~ sudo apt-get install libgtk-3-dev sudo apt-get install python3-dev python3-pip sudo -H pip3 install -U pip numpy sudo apt install python3-testresources sudo apt-get install libtbb-dev sudo apt-get install libatlas-base-dev gfortran sudo apt-get install libprotobuf-dev protobuf-compiler sudo apt-get install libgoogle-glog-dev libgflags-dev sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen cd ~ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip unzip opencv.zip unzip opencv_contrib.zip echo "Create a virtual environment for the python binding module" sudo pip install virtualenv virtualenvwrapper sudo rm -rf ~/.cache/pip echo "Edit ~/.bashrc" export WORKON_HOME=$HOME/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source /usr/local/bin/virtualenvwrapper.sh mkvirtualenv cv -p python3 pip install numpy echo "Procced with the installation" cd opencv-4.2.0 mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_C_COMPILER=/usr/bin/gcc-8 \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D WITH_TBB=ON \ -D BUILD_opencv_cudacodec=OFF \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=1 \ -D WITH_CUBLAS=1 \ -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 OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.2.0/modules \ -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \ -D BUILD_EXAMPLES=ON \ -D WITH_CUDNN=ON \ -D OPENCV_DNN_CUDA=ON \ -D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.7.6.5 \ -D CUDNN_INCLUDE_DIR=/usr/local/cuda/include \ -D CUDA_ARCH_BIN=7.5 .. nproc make -j8 sudo make install sudo /bin/bash -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf' sudo ldconfig # For Each Environment sudo cp -r ~/.virtualenvs/cv/lib/python3.8/site-packages/cv2 /usr/local/lib/python3.8/dist-packages echo "Modify config-3.8.py to point to the target directory" sudo nano /usr/local/lib/python3.8/dist-packages/cv2/config-3.8.py ``` PYTHON_EXTENSIONS_PATHS = [ os.path.join('/usr/local/lib/python3.8/dist-packages/cv2', 'python-3.8') ] + PYTHON_EXTENSIONS_PATHS ```
-
p3jitnath revised this gist
May 14, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -217,7 +217,7 @@ int main() { ``` Compile and execute: $ g++ -o test test.cpp `pkg-config opencv --cflags --libs` $ ./test ### References -
p3jitnath revised this gist
May 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -185,7 +185,7 @@ int main() { std::clock_t begin = std::clock(); try { cv::String filename = "image.png"; cv::Mat srcHost = cv::imread(filename, cv::IMREAD_GRAYSCALE); for(int i=0; i<1000; i++) { -
p3jitnath revised this gist
May 7, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # How to install OpenCV 4.2.0 with CUDA 10.1 on Ubuntu 20.04 LTS (Focal Fossa) Install updates and upgrade your system: -
p3jitnath renamed this gist
May 6, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # How to install OpenCV 4.2.0 with CUDA 10.1 on Ubuntu 20.04 (Focal Fossa) LTS Install updates and upgrade your system: -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -110,7 +110,7 @@ We will now proceed with the installation (see the Qt flag that is disabled to d -D CUDA_ARCH_BIN=7.5 .. If you want to build the libraries statically you only have to include the `-D BUILD_SHARED_LIBS=OFF` ``` $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON -D BUILD_SHARED_LIBS=OFF .. ``` -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -115,12 +115,12 @@ If you want to build the libraries statically you only have to include the *-D $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON -D BUILD_SHARED_LIBS=OFF .. ``` In case you do not want to include include CUDA set `-D WITH_CUDA=OFF` ``` $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=OFF -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON .. ``` If you want also to use CUDNN you must include those flags (to set the correct value of `CUDA_ARCH_BIN` you must visit https://developer.nvidia.com/cuda-gpus and find the Compute Capability CC of your graphic card) and also specify the CUDNN location: -D WITH_CUDNN=ON \ -D OPENCV_DNN_CUDA=ON \ @@ -137,7 +137,6 @@ Before the compilation you must check that CUDA has been enabled in the configur ``` If it is fine proceed with the compilation (Use nproc to know the number of cpu cores): $ nproc @@ -149,7 +148,7 @@ Include the libs in your environment $ sudo /bin/bash -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf' $ sudo ldconfig If you want to have available opencv python bindings in the system environment you should copy the created folder during the installation of OpenCV (` -D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages `) into the *dist-packages* folder of the target python interpreter: $ sudo cp -r ~/.virtualenvs/cv/lib/python3.8/site-packages/cv2 /usr/local/lib/python3.8/dist-packages -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ # How to install OpenCV 4.2.0 with CUDA 10.1 on Ubuntu 20.04 (Focal Fossa) Install updates and upgrade your system: $ sudo apt update $ sudo apt upgrade Install required libraries: * Generic tools: @@ -111,12 +111,14 @@ We will now proceed with the installation (see the Qt flag that is disabled to d If you want to build the libraries statically you only have to include the *-D BUILD_SHARED_LIBS=OFF* ``` $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON -D BUILD_SHARED_LIBS=OFF .. ``` In case you do not want to include include CUDA set *-D WITH_CUDA=OFF* ``` $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=OFF -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON .. ``` If you want also to use CUDNN you must include those flags (to set the correct value of CUDA_ARCH_BIN you must visit https://developer.nvidia.com/cuda-gpus and find the Compute Capability CC of your graphic card) and also specify the CUDNN location: -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -219,7 +219,7 @@ Compile and execute: $ g++ `pkg-config opencv --cflags --libs` -o test test.cpp $ ./test ### References [1] [raulqf](https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7) [2] [pyimagesearch](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) [3] [learnopencv](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -220,8 +220,8 @@ Compile and execute: $ ./test ### Source [1] [raulqf](https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7) [2] [pyimagesearch](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) [3] [learnopencv](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) [4] [Tzu-cheng](https://chuangtc.com/ParallelComputing/OpenCV_Nvidia_CUDA_Setup.php) [5] [Medium](https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961) -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -220,8 +220,8 @@ Compile and execute: $ ./test ### Source [1] [raulqf](https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7) [2] [pyimagesearch](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) [3] [learnopencv](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) [4] [Tzu-cheng](https://chuangtc.com/ParallelComputing/OpenCV_Nvidia_CUDA_Setup.php) [5] [Medium](https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961) -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -225,4 +225,3 @@ Compile and execute: - [learnopencv](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) - [Tzu-cheng](https://chuangtc.com/ParallelComputing/OpenCV_Nvidia_CUDA_Setup.php) - [Medium](https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961) -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # How to install OpenCV 4.2.0 with CUDA 10.1 on Ubuntu 20.04 (Focal Fossa) First of all install update and upgrade your system: -
p3jitnath revised this gist
May 6, 2020 . 1 changed file with 0 additions and 31 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -219,37 +219,6 @@ Compile and execute: $ g++ `pkg-config opencv --cflags --libs` -o test test.cpp $ ./test ### Source - [raulqf](https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7) - [pyimagesearch](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) -
p3jitnath created this gist
May 6, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,259 @@ # How to install OpenCV 4.2.0 with CUDA 10.1 on Ubuntu distro 20.04 (Focal Fossa) First of all install update and upgrade your system: $ sudo apt update $ sudo apt upgrade Then, install required libraries: * Generic tools: $ sudo apt install build-essential cmake pkg-config unzip yasm git checkinstall * Image I/O libs ``` $ sudo apt install libjpeg-dev libpng-dev libtiff-dev ``` * Video/Audio Libs - FFMPEG, GSTREAMER, x264 and so on. ``` $ sudo apt install libavcodec-dev libavformat-dev libswscale-dev libavresample-dev $ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev $ sudo apt install libxvidcore-dev x264 libx264-dev libfaac-dev libmp3lame-dev libtheora-dev $ sudo apt install libfaac-dev libmp3lame-dev libvorbis-dev ``` * OpenCore - Adaptive Multi Rate Narrow Band (AMRNB) and Wide Band (AMRWB) speech codec ``` $ sudo apt install libopencore-amrnb-dev libopencore-amrwb-dev ``` * Cameras programming interface libs ``` $ sudo apt-get install libdc1394-22 libdc1394-22-dev libxine2-dev libv4l-dev v4l-utils $ cd /usr/include/linux $ sudo ln -s -f ../libv4l1-videodev.h videodev.h $ cd ~ ``` * GTK lib for the graphical user functionalites coming from OpenCV highghui module ``` $ sudo apt-get install libgtk-3-dev ``` * Python libraries for python3: ``` $ sudo apt-get install python3-dev python3-pip $ sudo -H pip3 install -U pip numpy $ sudo apt install python3-testresources ``` * Parallelism library C++ for CPU ``` $ sudo apt-get install libtbb-dev ``` * Optimization libraries for OpenCV ``` $ sudo apt-get install libatlas-base-dev gfortran ``` * Optional libraries: ``` $ sudo apt-get install libprotobuf-dev protobuf-compiler $ sudo apt-get install libgoogle-glog-dev libgflags-dev $ sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen ``` We will now proceed with the installation (see the Qt flag that is disabled to do not have conflicts with Qt5.0). $ cd ~ $ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip $ unzip opencv.zip $ unzip opencv_contrib.zip $ echo "Create a virtual environtment for the python binding module" $ sudo pip install virtualenv virtualenvwrapper $ sudo rm -rf ~/.cache/pip $ echo "Edit ~/.bashrc" $ export WORKON_HOME=$HOME/.virtualenvs $ export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 $ source /usr/local/bin/virtualenvwrapper.sh $ mkvirtualenv cv -p python3 $ pip install numpy $ echo "Procced with the installation" $ cd opencv-4.2.0 $ mkdir build $ cd build $ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_C_COMPILER=/usr/bin/gcc-8 \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D WITH_TBB=ON \ -D BUILD_opencv_cudacodec=OFF \ -D ENABLE_FAST_MATH=1 \ -D CUDA_FAST_MATH=1 \ -D WITH_CUBLAS=1 \ -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 OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.2.0/modules \ -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \ -D BUILD_EXAMPLES=ON \ -D WITH_CUDNN=ON \ -D OPENCV_DNN_CUDA=ON \ -D CUDA_ARCH_BIN=7.5 .. If you want to build the libraries statically you only have to include the *-D BUILD_SHARED_LIBS=OFF* $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON -D BUILD_SHARED_LIBS=OFF .. In case you do not want to include include CUDA set *-D WITH_CUDA=OFF* $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-8 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=OFF -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -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 OPENCV_EXTRA_MODULES_PATH=~/downloads/opencv/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON .. If you want also to use CUDNN you must include those flags (to set the correct value of CUDA_ARCH_BIN you must visit https://developer.nvidia.com/cuda-gpus and find the Compute Capability CC of your graphic card) and also specify the CUDNN location: -D WITH_CUDNN=ON \ -D OPENCV_DNN_CUDA=ON \ -D CUDA_ARCH_BIN=7.5 \ -D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.7.6.5 \ -D CUDNN_INCLUDE_DIR=/usr/local/cuda/include \ Before the compilation you must check that CUDA has been enabled in the configuration summary printed on the screen. (If you have problems with the CUDA Architecture go to the end of the document). ``` -- NVIDIA CUDA: YES (ver 10.1, CUFFT CUBLAS NVCUVID FAST_MATH) -- NVIDIA GPU arch: 30 35 37 50 52 60 61 70 75 -- NVIDIA PTX archs: ``` If it is fine proceed with the compilation (Use nproc to know the number of cpu cores): $ nproc $ make -j8 $ sudo make install Include the libs in your environment $ sudo /bin/bash -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf' $ sudo ldconfig If you want to have available opencv python bindings in the system environment you should copy the created folder during the installation of OpenCV (* -D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages *) into the *dist-packages* folder of the target python interpreter: $ sudo cp -r ~/.virtualenvs/cv/lib/python3.8/site-packages/cv2 /usr/local/lib/python3.8/dist-packages $ echo "Modify config-3.8.py to point to the target directory" $ sudo nano /usr/local/lib/python3.8/dist-packages/cv2/config-3.8.py ``` PYTHON_EXTENSIONS_PATHS = [ os.path.join('/usr/local/lib/python3.8/dist-packages/cv2', 'python-3.8') ] + PYTHON_EXTENSIONS_PATHS ``` ### EXAMPLE TO TEST OPENCV 4.2.0 with GPU in C++ Verify the installation by compiling and executing the following example: ``` #include <iostream> #include <ctime> #include <cmath> #include "bits/time.h" #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/core/cuda.hpp> #include <opencv2/cudaarithm.hpp> #include <opencv2/cudaimgproc.hpp> #define TestCUDA true int main() { std::clock_t begin = std::clock(); try { cv::String filename = "/home/raul/Pictures/Screenshot_20170317_105454.png"; cv::Mat srcHost = cv::imread(filename, cv::IMREAD_GRAYSCALE); for(int i=0; i<1000; i++) { if(TestCUDA) { cv::cuda::GpuMat dst, src; src.upload(srcHost); //cv::cuda::threshold(src,dst,128.0,255.0, CV_THRESH_BINARY); cv::cuda::bilateralFilter(src,dst,3,1,1); cv::Mat resultHost; dst.download(resultHost); } else { cv::Mat dst; cv::bilateralFilter(srcHost,dst,3,1,1); } } //cv::imshow("Result",resultHost); //cv::waitKey(); } catch(const cv::Exception& ex) { std::cout << "Error: " << ex.what() << std::endl; } std::clock_t end = std::clock(); std::cout << double(end-begin) / CLOCKS_PER_SEC << std::endl; } ``` Compile and execute: $ g++ `pkg-config opencv --cflags --libs` -o test test.cpp $ ./test ### List of documented problems If you have problems with unsupported architectures of your graphic card with the minimum requirements from Opencv, you will get the following error: ``` CUDA backend for DNN module requires CC 5.3 or higher. Please remove unsupported architectures from CUDA_ARCH_BIN option. ``` It means that the DNN module needs that your graphic card supports the 5.3 Compute Capability (CC) version; in this [link](https://developer.nvidia.com/cuda-gpus) you can fint the CC of your card. Some opencv versions have fixed the minimum version to 3.0 but there is a clear move to filter above 5.3 since the half-precision precision operations are available from 5.3 version. To fix this problem you can modify the *CMakeList.txt* file located in *opencv > modules > dnn > CMakeList.txt* and set the minimum version to the one you have, but bear in mind that the correct functioning of this module will be compromised. However, if you only want GPU for the rest of modules, it could work. You can also select the target `CUDA_ARCH_BIN` option in the command to generate the makefile for your current target or modify the list of supported architectures: $ grep -r 'CUDA_ARCH_BIN' . //That prompts ./CMakeCache.txt The restriction is to have a higher version than 5.3, so you can modify the file by removing all the inferior arch to 5.3 ``` CUDA_ARCH_BIN:STRING=6.0 6.1 7.0 7.5 ``` Now, the makefile was created succesfully. Before the compilation you must check that CUDA has been enabled in the configuration summary printed on the screen. ``` -- NVIDIA CUDA: YES (ver 10.0, CUFFT CUBLAS NVCUVID FAST_MATH) -- NVIDIA GPU arch: 60 61 70 75 -- NVIDIA PTX archs: ``` *If you have any other problem try updating the nvidia drivers.* ### Source - [raulqf](https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7) - [pyimagesearch](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) - [learnopencv](https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/) - [Tzu-cheng](https://chuangtc.com/ParallelComputing/OpenCV_Nvidia_CUDA_Setup.php) - [Medium](https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961) - [Previous Gist](https://gist.github.com/raulqf/a3caa97db3f8760af33266a1475d0e5e)