OpenCV is an Open Source Computer Vision and Machine Learning software library.
With a bit of Python programming, you can turn a low-cost camera into an interesting sensor with OpenCV.
Let’s start with update && upgrade.
sudo apt-get update && sudo apt-get upgrade
There are bunch of dependancies need to be installed.
sudo apt install -y libtiff5 libpango-1.0-0 libavcodec58 libgdk-pixbuf2.0-0 libjasper1 libqt4-test libpangocairo-1.0-0 libswscale5 libilmbase23 libatk1.0-0 libgtk-3-0 libqtcore4 libcairo2 libwebp6 libavutil56 libcairo-gobject2 libopenexr23 libqtgui4 libavformat58
Update again before installing OpenCV.
sudo apt-get update
Installing OpenCV 4.1.0.25.
The newer versions for Raspberry Pi using this method probably be updated in the future.
sudo pip3 install opencv-contrib-python==4.1.0.25
Installing more libraries.
sudo apt-get install libfontconfig1-dev libcairo2-dev libgdk-pixbuf2.0-dev libpango1.0-dev libgtk2.0-dev libgtk-3-dev
Update again.
sudo apt-get update
Installing additional libraries.
sudo apt-get install libhdf5-dev libhdf5-serial-dev libatlas-base-dev
Testing
Run Python commands to test installed version of OpenCV is available.
Entering Python environment.
python3
Import OpenCV library.
import cv2
Run command to show version
cv2.__version__
This should show version 4.1.0
Exit from Python environment.
quit()