- 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:
pip install opencv-contrib-python - check installation by entering the Python REPL:
python3 - import tha library:
import cv2
brew install opencv
- Create a tmp folder for all archives:
mkdir ~/opencv4.5-tmp && cd ~/opencv4.5-tmp - Download opencv sources:
wget https://github.com/opencv/opencv/archive/4.5.1.zip -O opencv.zip - 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 BUILD_EXAMPLES=ON .. - Make the project:
make -j4 - Install opencv:
sudo make install