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
Then press Ctrl+x to leave - press again - press Y to save changes
Then press Enter to return to the terminal
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
Comment out the original code and replace it with a new source:
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
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
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
Wait for the installation to finish.
4. Test whether the installation is successful
enter:
python3
Then enter:
import cv2
No error is reported, indicating that the installation was successful.