Skip to content

Instantly share code, notes, and snippets.

@m3y54m
Last active February 3, 2023 21:49
Show Gist options
  • Save m3y54m/4f9b960e52f0da4e62e5a36f71d04fd7 to your computer and use it in GitHub Desktop.
Save m3y54m/4f9b960e52f0da4e62e5a36f71d04fd7 to your computer and use it in GitHub Desktop.
Build OpenCV 4 in Ubuntu

Build OpenCV 4 in Ubuntu

Install prerequisites

sudo apt update && sudo apt install -y cmake g++ wget

Download latest version of OpenCV 4 from GitHub

Create a directory for OpenCV installation:

cd ~
mkdir opencv
cd opencv

Download OpenCV core modules:

wget -O https://github.com/opencv/opencv/archive/refs/tags/4.7.0.tar.gz

Download OpenCV extra modules:

wget -O https://github.com/opencv/opencv_contrib/archive/refs/tags/4.7.0.tar.gz

Extract the source

tar -xzf opencv-4.7.0.tar.gz
tar -xzf opencv_contrib-4.7.0.tar.gz 

The directory structure after extraction should be like this:

.
├── opencv-4.7.0
├── opencv-4.7.0.tar.gz
├── opencv_contrib-4.7.0
└── opencv_contrib-4.7.0.tar.gz

2 directories, 2 files

You can remove *.tar.gz files if you want.

Create build directory

mkdir build
cd build

Configure

cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.7.0/modules ../opencv-4.7.0

Build

make -j8

Install

sudo make install

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment