Skip to content

Instantly share code, notes, and snippets.

@andmax
Last active April 20, 2023 12:08
Show Gist options
  • Save andmax/7cbff81af9b685a83f74faa476f33699 to your computer and use it in GitHub Desktop.
Save andmax/7cbff81af9b685a83f74faa476f33699 to your computer and use it in GitHub Desktop.
Hints on installing OpenCV (4.5.5) on Ubuntu (20.04)
0. A better option than below guidelines is to install OpenCV in Python via:
pip install opencv-python
sudo apt update
sudo apt install libgl1
1. Remove opencv installed by apt (probably not the most recent version)
2. Clean-up and update apt (so dependencies can be installed)
3. Install dependencies
4. Set gcc/g++ to maximum allowed version (8 for cuda-10.2)
5. Download and un-zip opencv
6. Download opencv_contrib (necessary for OpenCV CUDA support)
7. Compile and install opencv
The commands below execute above guidelines:
sudo apt purge *libopencv*
sudo apt autoremove
sudo apt autoclean
sudo apt update
sudo apt install build-essential cmake python3-numpy python3-dev python3-tk libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev libdc1394-dev libeigen3-dev libgtk-3-dev libvtk7-qt-dev zlib1g unzip wget ninja-build
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
wget https://github.com/opencv/opencv/archive/4.5.5.zip
unzip 4.5.5.zip
git clone https://github.com/opencv/opencv_contrib.git
cd opencv-4.5.5
mkdir build
cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=RELEASE -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DWITH_CUDA=ON -DBUILD_EXAMPLES=ON -DBUILD_opencv_world=OFF ..
sudo ninja install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment