树莓派4B学习笔记1:openCV的安装

tech2025-09-18  1

说明

本文是作者按记忆回忆出的安装过程,尚未再次实验,可略作参考。 ##创建时间:2020年9月4日 ##作者:Yuncheng.Li ##版本:1.0 ##上次修改时间:无 ##树莓派版本:4B;2+32G;

前期准备

更换镜像源

在终端输入以下指令:sudo nano /etc/apt/sources.list sudo nano /etc/apt/sources.list.d/raspi.list 编辑 /etc/apt/sources.list 文件,删除原文件所有内容,用以下内容取代:deb http://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os/raspbian/ buster main non-free contrib rpi deb-src http://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os/raspbian/ buster main non-free contrib rpi 编辑 /etc/apt/sources.list.d/raspi.list 文件,删除原文件所有内容,用以下内容取代:deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui 使用ctrl+o保存,点击回车确认保存,然后ctrl+x退出直接ctrl+x也会提示保存,需要输入y确认更新系统和目录sudo apt-get update sudo apt-get upgrade

更换pip源

临时换源 pip install scrapy-i pypi.tuna.tsinghua.edu.cn/simple/ 即加上控制符-i与国内源的地址``永久换源首次换源需要创建一个文件sudo mkdir ~/.pip ls .pip sudo nano pip.conf 在打开的文件中输入以下内容[global] timeout = 10 index-url = http://mirrors.aliyun.com/pypi/simple/ extra-index-url = http://pypi.douban.com/simple/ [install] trusted-host = mirrors.aliyun.com pypi.douban.com ctrl+o,回车,ctrl+x退出文本编辑器一般国内源的地址阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple/ 豆瓣 http://pypi.douban.com/simple/ 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

树莓派官方摄像头

在命令行输入以下命令:sudo nano /etc/modules 在文件末尾添加一行:bcm2835-v4l2 拍照测试raspistill -o image.jpg 拍摄了一张照片,命名为image.jpg,并保存在/pi/home的路径下

安装openCV

python2版本openCV的安装

在终端输入以下命令:sudo apt-get install libopencv-dev sudo apt-get install python-opencv 在python2中测试openCV在终端中输入 python2 并回车 import cv2 cv2.__version__

python3版本的安装

在终端输入以下命令:pip3 install opencv-python pip3 install opencv-contrib-python==4.1.0.25 sudo apt-get install libatlas-base-dev sudo apt-get install libjasper-dev -y sudo apt-get install libqtgui4 sudo apt-get install python3-pyqt5 -y sudo apt-get install libqt4-test sudo apt-get install libhdf5-dev -y 若下载速度缓慢可尝试切换源 在python3中测试openCV在终端中输入 python2 并回车 import cv2 cv2.__version__

写在最后

对于python3版本的openCV安装总会是一波三折的。openCV并不是一个“软件”,不能直接get就装好,而且更新速度很快,导致网上很多教程都不能成功,同时网络问题也让人头疼。当时安装一个组件,电信的校园网不行,移动的校园网不行,电信的热点不行,移动的热点也不行,结果一回家10分钟就下完了,属实离谱。

希望有好兄弟告诉我怎么给代码加行号 感谢前人的所有教程

最新回复(0)