This is a quick guide showing how to install OpenCV (Open Computer Vision Library) software on a Raspberry Pi board. We tested this installation on Raspberry Pi OS 64-bit. OpenCV is an open-source library for computer vision and machine learning that comes with tools and algorithms for image processing, video analysis, and machine learning applications.
There are many ways for installing OpenCV on Raspberry Pi, you can install with pip on a virtual environment, install it using apt install or compile the software from source. In this guide, we’ll show you two options:
a) Installing OpenCV on Raspberry Pi with pip on Virtual Environment (Recommended)
b) Installing OpenCV on Raspberry Pi with apt
Prerequisites
Before proceeding:
- You need a Raspberry Pi board.
- You should have a Raspberry Pi running Raspberry Pi OS (32-bit or 64-bit).
- You should be able to establish an SSH connection with your Raspberry Pi.
a) Installing OpenCV on Raspberry Pi with pip on Virtual Environment (Recommended)
Having an SSH connection established with your Raspberry Pi, update and upgrade your Raspberry Pi, if any updates are available. Run the following command:
sudo apt update && sudo apt upgrade -y
Run the next command which should print in your terminal a Python version 3.X:
python --version
Install pip3 and Python 3 Virtual environment:
sudo apt install -y python3-pip python3-virtualenv
Create a Virtual Environment
We’ll install the OpenCV library in a virtual environment. Creating a virtual environment will isolate the Python libraries we’re using, in this case, the OpenCV library, from the rest of the system.
We’ll create our virtual environment on a directory on our Desktop. Enter the following command on a Terminal window to move to the Desktop:
cd ~/Desktop
Create a folder for your project. This is where we’ll create the virtual environment and install the library. We’ll create a folder called projects.
mkdir projects
Move to the newly created folder:
cd ~/Desktop/projects
Create a virtual environment for this directory called myenv. This must be the same directory where we’ll install the OpenCV library. Replace myenv with the desired name for your virtual environment.
python3 -m venv projectsenv
Then, you can run the following command to check that the virtual environment is there.
ls -l
Activate the virtual environment:
source projectsenv/bin/activate
Your prompt should change to indicate that you are now in the virtual environment.
No comments:
Post a Comment