본문 바로가기

Linux

Install OpenCV + Cuda + cuDNN + TensorRT on Ubuntu 18.04

반응형

1. Install OpenCV

a) install required packages

$ sudo apt-get install build-essential cmake

$ sudo apt-get install pkg-config

$ sudo apt-get install libjpeg-dev libtiff5-dev libpng-dev

$ sudo apt-get install ffmpeg libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev

$ sudo apt-get install libv4l-dev v4l-utils

$ sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 

$ sudo apt-get install libgtk-3-dev

$ sudo apt-get install mesa-utils libgl1-mesa-dri libgtkgl2.0-dev libgtkglext1-dev  

$ sudo apt-get install libatlas-base-dev gfortran libeigen3-dev

$ sudo apt-get install python3-dev python3-numpy

 

b) download source codes for opencv-4.4.0 and unzip

$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.4.0.zip

$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.4.0.zip

$ unzip opencv.zip

$ unzip opencv_contrib.zip

 

c) create folder 'build' under the folder 'opencv-4.4.0' and move to 'build' folder. Next, set compile flags

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=OFF -D WITH_IPP=OFF -D WITH_1394=OFF -D BUILD_WITH_DEBUG_INFO=OFF -D BUILD_DOCS=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=OFF -D BUILD_PACKAGE=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D WITH_QT=OFF -D WITH_GTK=ON -D WITH_OPENGL=ON -D BUILD_opencv_python3=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.4.0/modules -D WITH_V4L=ON  -D WITH_FFMPEG=ON -D WITH_XINE=ON -D OPENCV_ENABLE_NONFREE=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D OPENCV_SKIP_PYTHON_LOADER=ON -D OPENCV_GENERATE_PKGCONFIG=ON ../

 

d) do compile 

$ time make -j$(nproc)

 

e) install

$ time make -j$(nproc)

 

2. Install CUDA 11.03 & cuDNN 8.x

a) do following steps sequentially (for CUDA download and installation)

$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin

$ sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600

$ wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda-repo-ubuntu1804-11-0-local_11.0.3-450.51.06-1_amd64.deb 

$ sudo dpkg -i cuda-repo-ubuntu1804-11-0-local_11.0.3-450.51.06-1_amd64.deb 

$ sudo apt-key add /var/cuda-repo-ubuntu1804-11-0-local/7fa2af80.pub

$ sudo apt-get update

$ sudo apt-get -y install cuda

 

b) download cuDNN 8.x corresponding to CUDA 11.03

developer.nvidia.com/rdp/cudnn-download

c) unzip the downloaded files

$ tar xvf cudnn-11.0-linux-x64-v8.0.5.39.tgz

 

d) copy files to the folder 'cuda-11.0'

$ cd cuda

$ sudo cp include/cudnn* /usr/local/cuda-11.0/include

$ sudo cp lib64/libcudnn* /usr/local/cuda-11.0/lib64/

$ sudo chmod a+r /usr/local/cuda-11.0/lib64/libcudnn*

 

 

3. Install TensorRT

a) via deb file or tar file

https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#downloading