先到官网下载最新的树莓派系统(注意:树莓派4不支持以前的老系统,请刷buster系统)
下载完之后使用镜像烧录工具进行烧录:
更换为国内源:
sudo nano /etc/apt/sources.list
注释掉之前的,添加如下两行:
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
为了pip安装软件快一点,增加一个国内pip源:
sudo nano /etc/pip.conf
添加一行(其它不动):
index-url = https://mirrors.aliyun.com/pypi/simple
sudo apt-get update
安装一下google-pinyin输入法:
sudo apt-get install fcitx fcitx-googlepinyin fcitx-module-cloudpinyin fcitx-sunpinyin
最后重启:
reboot
sudo raspi-config
更新和升级软件包:
sudo apt-get update
sudo apt-get upgrade
安装图像I/O包:
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev
安装视频I/O包,方便获取 视频流:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
为编译 highgui模块,我们需要安装GTK开发库:
sudo apt-get install libfontconfig1-dev libcairo2-dev
sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
安装一些额外项来优化opencv许多内部操作(如矩阵操作):
sudo apt-get install libatlas-base-dev gfortran
安装适用于HDF5数据集和Qt GUI:
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
虚拟环境隔离了其它环境,比较方便不易受到影响,类似Anaconda创建的环境
现在安装 virtualenv 和 virtualenvwrapper:
sudo pip3 install virtualenv virtualenvwrapper
sudo nano ~/.bashrc
在底部添加加以下几行:
#virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bashrc
使用Python 3 创建一个名为py3(可自己随便起)的Python虚拟环境:
mkvirtualenv py3 -p python3
进入创建的虚拟环境py3:
workon py3
pip3 install opencv-contrib-python
workon py3
python3
>>> import cv2
>>> cv2.__version__
'3.4.3'
Reference:
https://www.jianshu.com/p/768f0181672b
https://www.pyimagesearch.com/2019/09/16/install-opencv-4-on-raspberry-pi-4-and-raspbian-buster/
https://blog.csdn.net/Cloud_1234_5678/article/details/89067707