树莓派+opencv安装编译(亲测成功)

来源:https://www.jianshu.com/p/fcc319d1ddd4 侵删
我使用的树莓派是2018.11.13版本
链接:https://pan.baidu.com/s/148C00NdkQozP2nFc5-p9Pw
提取码:porw

1.首先,将源设为清华源
输入命令sudo nano /etc/apt/sources.list
将原源注释掉,添加:
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

2.下载依赖包
sudo apt-get purge wolfram-engine --assume-yes
sudo apt-get purge libreoffice* --assume-yes
sudo apt-get clean --assume-yes
sudo apt-get autoremove --assume-yes
sudo apt-get update && sudo apt-get upgrade --assume-yes
sudo apt-get install build-essential cmake pkg-config --assume-yes
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev --assume-yes
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev --assume-yes
#注意是libv4l而不是libv41
sudo apt-get install libxvidcore-dev libx264-dev --assume-yes
sudo apt-get install libgtk2.0-dev libgtk-3-dev --assume-yes
sudo apt-get install libcanberra-gtk* --assume-yes
sudo apt-get install libatlas-base-dev gfortran --assume-yes
sudo apt-get install python2.7-dev python3-dev --assume-yes

3.下载opencv
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.3.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.3.zip
unzip opencv_contrib.zip

4.将数据交互区增大
sudo nano /etc/dphys-swapfile
将CONF_SWAPSIZE=100改为CONF_SWAPSIZE=1024
重启服务
sudo /etc/init.d/dphys-swapfile stop && sudo /etc/init.d/dphys-swapfile start

5.编译配置
先在opencv-3.4.3文件夹中建立build文件夹,再执行命令
cd ~/opencv-3.4.3/build
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.3/modules
-D ENABLE_NEON=ON
-D ENABLE_VFPV3=ON
-D WITH_GTK=ON
-D BUILD_TESTS=OFF
-D INSTALL_C_EXAMPLES=OFF
-D INSTALL_PYTHON_EXAMPLES=OFF
-D BUILD_EXAMPLES=OFF …

6.编译
sudo make -j4 #加上j4速度较快,而只有make的话需要编译4小时左右

7.安装
sudo make install && sudo ldconfig

8.装载摄像头驱动
sudo nano /etc/modules
添加 bcm2835-v4l2

9.将交互区改回100
sudo nano /etc/dphys-swapfile
将CONF_SWAPSIZE=1024改为CONF_SWAPSIZE=100

10.重启

你可能感兴趣的:(树莓派)