本文为RPi3上Python3.5安装opencv-python指令汇总
注:RPi3基于ARM架构,并不支持https://pypi.python.org/pypi上的opencv-contrib-python,目前只支持Python3 通过pip3 install opencv-contrib-python从https://www.piwheels.org/simple/opencv-contrib-python/安装
更新升级
Step 1: 更新树莓派的系统与内核并升级pip
sudo apt-get update
sudo apt-get upgrade
sudo pip3 install -U pip
Step 2:安装numpy
sudo pip3 install numpy
Step 3:安装OpenCV
sudo pip3 install opencv-contrib-python
pypi.python.org不支持在RPi上安装opencv-python,但piwheels.org支持,不过目前只支持Python3,可访问https://www.piwheels.org/simple/opencv-contrib-python/查看
Step 4:Python调用OpenCV
python3
>>>import cv2
>>>出现类似error,因为修复了,所以没了
ImportError: libhdf5_serial.so.100: cannot open shared object file: No such file or directory
Step 5:出错?!看提示,缺什么补什么!
推荐一个好网站:https://www.howtoinstall.co/en/
Raspbian-stretch实际上是Debain-streth,选择Debain ==> Debain 9
前向匹配选出你要安装的库文件,如这里libhdf5,得到:https://www.howtoinstall.co/en/debian/stretch/?condition=starts-with&search=libhdf5,这里我选择了两个:
sudo apt-get update
sudo apt-get install libhdf5-dev
sudo apt-get update
sudo apt-get install libhdf5-serial-dev
由于RPi ARM架构的特殊性,下面还会有很多错误,这样一个一个修复太慢了,根据以前本地编译的经验:https://www.jianshu.com/p/7756fc65277b 执行如下代码:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev libatlas-base-dev gfortran
本人是技术小白,不排除上述代码的多余性,所以报错不用管。不过确实有用,之后只有几个错误,都通过https://www.howtoinstall.co/en/ 查询修复了
最终成果
提示
putty支持多行复制,右键点击粘贴,依次执行的功能