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
(Optional) 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 autoconf automake libtool curl make g++ unzip
wget <https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz>
tar -xzvf protobuf-all-3.6.1.tar.gz
cd protobuf-3.6.1
./configure
make
sudo make install
sudo ldconfig # Bu komut, paylaşılan kitaplık bağlantılarını yeniler.
protobuf yukaridaki gibi kurulduysa bu satıra gerek yok.
$ 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 ~/Downloads
$ wget -O opencv.zip <https://github.com/opencv/opencv/archive/refs/tags/4.5.2.zip>
$ wget -O opencv_contrib.zip <https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.2.zip>
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ echo "Create a virtual environtment for the python binding module (OPTIONAL)"
$ 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.5.2
$ mkdir build
$ cd build
CC=gcc-10 CXX=g++-10 cmake \\
-D CMAKE_BUILD_TYPE=RELEASE \\
-D CMAKE_INSTALL_PREFIX=/usr/local \\
-D OPENCV_EXTRA_MODULES_PATH=/home/recepaydogdu/Downloads/opencv_contrib-4.5.2/modules/ \\
-D BUILD_opencv_sfm=OFF \\
-D WITH_CUDA=ON \\
-D WITH_CUBLAS=ON \\
-D WITH_CUDNN=ON \\
-D CUDA_ARCH_BIN="8.9" \\
-D CUDA_ARCH_PTX="" \\
-D CUDA_FAST_MATH=ON \\
-D ENABLE_FAST_MATH=ON \\
-D OPENCV_DNN_CUDA=ON \\
-D ENABLE_NEON=OFF \\
-D BUILD_TIFF=ON \\
-D WITH_QT=OFF \\
-D WITH_TBB=ON \\
-D BUILD_TBB=ON \\
-D WITH_FFMPEG=OFF \\
-D OPENCV_ENABLE_NONFREE=ON \\
-D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages \\
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python3.8 \\
-D BUILD_TESTS=OFF \\
-D BUILD_PERF_TESTS=OFF \\
-D OPENCV_GENERATE_PKGCONFIG=ON \\
-D BUILD_EXAMPLES=OFF ..