sudo apt update && sudo apt install -y cmake g++ wget
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
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.
mkdir build
cd build
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.7.0/modules ../opencv-4.7.0
make -j8
sudo make install