树莓派安装opencv的教程层出不穷,但是能用的很少。我这个教程是亲自安装成功的。
我之前安装过好几次opencv2.49都失败了,唯独这个opencv3.1成功了。
下面开始安装吧
1.准备
sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libjpeg-dev libjasper-dev libdc1394-22-dev
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 libatlas-base-dev gfortran
2.下载opencv
cd /home/pi
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.0.0
3.安装opencv_contrib:
cd /home/pi
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.0.0
4.安装python
sudo apt-get install python2.7-dev
5.安装opencv
进入opencv3.1文件夹
cmake . # cmake+空格+"."
sudo make
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
6.编译sample
cd ~/opencv/samples
sudo cmake .
sudo make -j $(nproc)
7.运行测试程序
进入opencv3.1文件夹
cd samples
cd cpp/
./cpp-example-facedetect lena.jpg
我在网上找了个图片, 进行测试。