本人在安装opencv时发现不同教程的安装包每次不全,在查阅数篇博客,摸索了一下,整理如下。
我的树莓派版本是这样的:
syz@raspberrypi:~ $ uname -m
aarch64
syz@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
本篇适用于和我一样版本12。其他版本需要在换源时更换不同接口,具体可以在清华大学镜像源网站按照自己版本选择,后面哪些地方需要替换我也会提到。
清华大学镜像源:raspbian | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
raspbian | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirrorraspbian 使用帮助 | 镜像站使用帮助 | 清华大学开源软件镜像站,致力于为国内和校内用户提供高质量的开源软件镜像、Linux 镜像源服务,帮助用户更方便地获取开源软件。本镜像站由清华大学 TUNA 协会负责运行维护。https://mirrors.tuna.tsinghua.edu.cn/help/raspbian/
和我一样是aarch64架构的需要看这里:
debian | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
debian | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirrordebian 使用帮助 | 镜像站使用帮助 | 清华大学开源软件镜像站,致力于为国内和校内用户提供高质量的开源软件镜像、Linux 镜像源服务,帮助用户更方便地获取开源软件。本镜像站由清华大学 TUNA 协会负责运行维护。https://mirrors.tuna.tsinghua.edu.cn/help/debian/
树莓派系统安装后默认国外源,由于墙的限制,安装起来会非常的慢,所以我们需要换成国内镜像网站提供的源,这里我选择清华大学源。
sudo nano /etc/apt/sources.list
打开配置文件后,将原本存在的代码的每一行最前面用#注释掉,在最后添加上从镜像源网站复制的镜像。
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
编辑完了之后,ctrl+o写入,再是 ctrl+x退出
操作同上,版本相同的直接复制
sudo nano /etc/apt/sources.list.d/raspi.list
改镜像
deb http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main
gpg --keyserver keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E
gpg --export --armor 9165938D90FDDD2E | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
在将树莓派切换到清华大学镜像源后安装opencv变得十分简单
只需要输入以下指令
sudo apt-get install python3-opencv
等安装结束后输入以下指令确认安装是否成功
python
import cv2
cv2.__version__
这样就是成功了
本人也是开始入门树莓派,欢迎大家交流,以及批评指正!