Beginner Raspberry Pi - (6) Install OpenCV and USB camera configuration on Raspberry Pi

Table of contents

1. Install OpenCV

1.1 Preface

1.2 Source change and source content update

1.3 Installation dependencies

1.4 Download the whl package

 1.5 Install OpenCV

1.6 Check installation

2. USB camera configuration (check OpenCV installation at the same time)

2.1 Preface

2.2Python calls the cv2 library to check whether it is installed in place


1. Install OpenCV

1.1 Preface

Here  I would like to express my gratitude to stray cats. This article refers to Super Simple Teaching You to Install OpenCV on Raspberry Pi (2)

As I said in Raspberry Pi for Beginners—(1) Copying the system, the purpose of my copying system is to expand the capacity, and then install OpenCV to run artificial intelligence. My system is a 32-bit system downloaded from the official website, and the Python version is 3.9 . 2. It is recommended that you back up or make a copy of the SD card before installing OpenCV, so that you will not have to start all over again when you make a mistake.

getconf LONG_BIT    //查询系统位数
python              //查询Python版本

1.2 Source change and source content update

Since the Raspberry Pi software source is a foreign website, the speed of downloading the software and building the server is relatively slow. Replacing the domestic source can improve the download speed and is not prone to various errors.

Enter the command to change the source

wget -qO- https://tech.biko.pub/resource/rpi-replace-apt-source-buster.sh | sudo bash

Enter the command to update the source content

sudo apt-get update

sudo apt-get upgrade

1.3 Installation dependencies

Enter the following command to install dependencies

sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install python3-pyqt5
sudo apt install libqt4-test

As long as there is no red warning, there is no problem

1.4 Download the whl package

Enter the command uname -a to query the system architecture

whl package download URL https://piwheels.org/project/opencv-python/#install

I downloaded this, you can choose according to your own system architecture and Python version

After downloading, find a way to put the whl package into the Raspberry Pi, for remote transmission and U disk copying.

 1.5 Install OpenCV

cd Desktop //Enter the desktop

pip install opencv_python-4.5.5.64-cp39-cp39-linux_armv7l //Install whl

successfully installed

1.6 Check installation

Enter the command python

Type import numpy

Type numpy.__version__

At this point return the numpy version number

Type import cv2

Enter cv2.__version__

Return the cv2 version number at this time

Here it means that the installation has been successful, and then you can check the installation of OpenCV in a practical way through the USB camera

2. USB camera configuration (check OpenCV installation at the same time)

2.1 Preface

Here I would like to express my gratitude to @诗草, this article refers to the Raspberry Pi and OpenCV to realize face recognition (face recognition)

The premise of testing the camera is that the camera interface has been enabled in the Raspberry Pi

Next, enter lsusb before and after inserting the USB camera to see if there is a device connected

First check whether the camera can be used normally, we use the tool luvcview to view the real-time video of the camera

Enter the command sudo apt-get install luvcview to install luvcview

Enter the command luvcview -s 1080x720 //1080*720 represents the resolution of the collection

At this time, we can see the real-time picture collected by the camera.

Enter Ctrl+C to exit

2.2Python calls the cv2 library to check whether it is installed in place

Download related programs git clone https://gitee.com/jeebus/Facial_Recognition.git

Saved in the Facial_Recognition folder by default

Enter the command cd Facial_Recognition

Enter the command python3 simpleCamTest.py

If the OpenCV library is not installed in place, then we will report an error when executing the above py file. If it is executed normally, it will be as shown in the figure.

Enter Ctrl+C to exit

Guess you like

Origin blog.csdn.net/shenqijiji/article/details/124531057