Raspberry Pi - Install OpenCV

My topic needs to use the Raspberry Pi to record video and send the video processing back to the back-end server, so OpenCV needs to be installed.
Installing OpenCV refers to a lot of articles, but they are all unsuccessful. Only I followed this blogger to succeed: super simple to teach you to install opencv on the Raspberry Pi (1)

1. Raspberry Pi system installation

Refer to my previous article: Raspberry Pi - Raspberry Pi System Installation (very simple)

2. Install OpenCV

2.1, change the source (there are two places)

Open a terminal and type:

sudo nano /etc/apt/sources.list

2.2. Replace the code (the first place)

In the opened /etc/apt/sources.list terminal page, comment out the original code and replace it with the new code

new source:

deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi

insert image description here

Then press Ctrl+x to leave - press again - press Y to save changes

insert image description here
insert image description here

Then press Enter to return to the terminal

insert image description here
Just change one here, and then change to the second.

2.3. Replace the code (second place)

Also enter:

sudo nano /etc/apt/sources.list.d/raspi.list

insert image description here
Comment out the original code and replace it with a new source:

deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui

insert image description here

After changing it, press Ctrl+x——Y—Enter

The source of the two places here has been replaced, and then it needs to be updated to be considered a complete replacement.

2.4, update update

This step must be there, enter in the terminal

sudo apt-get update

insert image description here

3. Install OpenCV

After the above steps are completed, OpenCV can be installed. My Raspberry Pi has python 2.7.16 and 3.7.3
installed based on python3 (I will install websockets later and need to be under python3):

sudo apt-get install python3-opencv -y

insert image description here
Wait for the installation to finish.

4. Test whether the installation is successful

enter:

python3

Then enter:

import cv2

insert image description here
No error is reported, indicating that the installation was successful.

Guess you like

Origin blog.csdn.net/weixin_48501651/article/details/127830778