树莓派3B+编译安装opencv3

一、更新源

1
2
mv sources.list /etc/apt/sources.list 
mv raspi.list /etc/apt/sources.list.d/raspi.list

更新源的配置,注意文件存放的位置
文件sources.list和raspi.list具体内容如下

sources.list文件:

deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main contrib non-free rpi
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb http://mirrors.neusoft.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

raspi.list文件:

1
2
3
4
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main ui
deb http://mirrors.aliyun.com/raspbian/raspbian/ stretch main ui
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main ui
deb http://mirrors.neusoft.edu.cn/raspbian/raspbian/ stretch main ui

在终端执行更新命令:

1
2
sudo apt-get update
sudo apt-get upgrade

二、安装依赖包

1
2
3
4
5
6
7
8
9
sudo apt-get install build-essential cmake git pkg-config 
sudo apt-get install libjpeg8-dev
sudo apt-get install libtiff5-dev
sudo apt-get install libjasper-dev
sudo apt-get install libpng12-dev

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran

注意:降级安装
有些安装包依赖的版本低需要降级安装,如下,对depends后面的进行降级安装

1
sudo aptitude install xxxx

三、下载源码

1
git clone https://github.com/opencv/opencv.git

四、编译

1
2
3
4
cmake dir/of/opencv/source
sudo make -j4
sudo make install
sudo ldconfig