Install OpenCV On Raspberry Pi With Command
Table of Contents
Introduction
This tutorial describes the steps necessary to Install OpenCV On Raspberry Pi 3. The process is simple and only requires a few minutes. Once installed, you will have access to a wide variety of example programs that demonstrate the power of this toolkit.
Installing OpenCV on a Raspberry Pi is a relatively easy method. In this guide, we’ll show you how to install OpenCV 4 on your Raspberry Pi 4.
A great way to get started with computer vision is to use the OpenCV library on a Raspberry Pi. OpenCV is a powerful library that can be used to develop computer vision applications
Required Material
In this tutorial, you will learn how to install OpenCV on your Raspberry Pi. You will need the following items to complete this tutorial: –
- Raspberry Pi
- MicroSD card
- USB power supply
- Keyboard
- Mouse First
First, make sure you have a good power supply and a reliable SD card. We recommend using a 16GB SD card or larger.
Check the Raspberry Pi OS version on Raspberry PI
1 |
cat /etc/os-release |
Here is what mine:
1 2 3 4 5 6 7 8 9 10 |
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)" NAME="Raspbian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs" |
See I am using “Raspbian GNU/Linux version 11”.
Set Up Your Raspberry Pi
First, we need to make sure that our Raspberry Pi is up to date. We can do this by running the following commands: Cool, we’re ready. Let’s update the Pi:
1 |
sudo apt-get update && sudo apt-get upgrade |
Now that our Raspberry Pi is up to date.
Install Python
Once we have updated Raspberry Pi OS, we go to the terminal and type python3
and as you will notice, python is already installed, this time in version 3.9.2.
If you don’t have Python then use the following command will download Python directly onto your machine.
1 |
<span class="enlighter-text">sudo apt-get install python3</span> |
Install pip
Python package manager (Pip) is a package manager for Python that allows you to install and manage software packages written in Python.
1 |
sudo apt-get install python3-pip |
This will install the latest version of pip. Once pip is installed, you can use it to install packages from the Python Package Index, a repository of software written in Python.
Install OpenCV On Raspberry Pi With Command
We are going to install OpenCV version 4.1.0.25.
1 |
sudo apt-get install python-opencv |
The command overhead will install all required packages to run OpenCV.
The installation is complete
To verify the installation, import the cv2
module and print the OpenCV version:
To verify the installation, import the cv2
module and print the OpenCV version:
1 2 |
import cv2 print(cv2.__version__) |
Conclusion
After following these steps, you will have OpenCV installed on your Raspberry Pi.