How to Install OpenCV to Raspberry Pi

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()
Other Tutorials
High-level Steps: Prepare a Micro SD Card Download Raspbian ImageFlash the SD CardStart Raspberry Pi and Configure Find Raspberry Pi ...
There are a few different types of accessing Raspberry Pi remotely. In this post I'll introduce the following types: SSH ...
When you experimenting with Raspberry Pi, you often wish to go back to a "clean" working state, especially after messing ...
Raspberry Pi itself already has a lot of potential but with Camera, it makes even more interesting. You can easily ...
OpenCV is an Open Source Computer Vision and Machine Learning software library.With a bit of Python programming, you can turn ...
Having a database comes in handy in some Raspberry Pi projects. SQLite gives you a lightweight database with Structured Query ...
LCD Screen is a much more effective way to communicate the current status with a user, compare to beeping sound ...
Although there are few options for wired audio out from Raspberry Pi, a wireless Bluetooth speaker may be useful for ...
Don't you love robotic voice coming out from Raspberry Pi?Pico Text-to-Speech engine will give Raspberry Pi ability to speak without ...
Raspberry Pi Zero has HDMI, Bluetooth and USB for potential Audio Outputs but it is missing PWM audio output compared ...