- open the terminal
- check Python3 installation:
python3 --version - go to official website to learn details: https://pypi.org/project/opencv-python/
- choose the most complete package and run:
python3 -m pip install opencv-contrib-pythonoften you will not find the pip installed by default, therefore use the corresponding steps from the following instructions to install it (https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/) - check installation by entering the Python REPL:
python3 - import the library:
import cv2
- Check pre-requisites: cmake and the compilers gcc, g++ should be installed
- We will use the following link: https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html as the basis for our instructions
- Let's open the most recent release of opencv to the date of this video capturing: https://github.com/opencv/opencv/releases/tag/4.5.1
- Create a tmp folder for all archives:
mkdir ~/opencv4.5-tmp && cd ~/opencv4.5-tmp - We need to download opencv sources:
wget https://github.com/opencv/opencv/archive/4.5.1.zip -O opencv.zip - We need to download opencv-contrib sources:
wget https://github.com/opencv/opencv_contrib/archive/4.5.1.zip -O opencv_contrib.zip - Unzip the opencv files:
unzip opencv.zip - Unzip the opencv-contrib files:
unzip opencv_contrib.zip - Move the files to simple directories:
mv opencv-4.5.1/ opencv - Move opencv-contrib files to simple directories:
mv opencv_contrib-4.5.1/ opencv_contrib - Make build directory:
cd opencv && mkdir build && cd build - Copy and run the following command. Install cmake if it is not available on the system.
cmake -D CMAKE_BUILD_TYPE=DEBUG \ -D CMAKE_INSTALL_PREFIX=~/opencv4.5-custom \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv4.5-tmp/opencv_contrib/modules \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D BUILD_EXAMPLES=ON .. - Make the project:
make -j4 - Install opencv:
sudo make install - Ensure that it is updated in the library storage:
sudo ldconfig