前提准备
1.更改清华源
sudo nano /etc/apt/sources.list # 编辑 `/etc/apt/sources.list` 文件,删除原文件所有内容,用以下内容取代:
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
sudo nano /etc/apt/sources.list.d/raspi.list # 编辑 `/etc/apt/sources.list.d/raspi.list` 文件,删除原文件所有内容,用以下内容取代:
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
2.更改python3 为默认版本
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
3.安装远程桌面
sudo apt-get update
or
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install tightvncserver
sudo apt-get install xrdp
sudo service xrdp restart
4.安装OPENCV 3.4.0 前的准备
把opencv这两个文件传到这里
cd /home/pi/Downloads
第一步 安装好numpy
这个是python的科学计算库
sudo pip3 install numpy
在树莓派设置中把根目录扩大到整个SD卡,选择Expand Filesystem,将根目录扩展到这个SD卡,充分利用SD卡的存储空间。如果不进行这一步,后续命令会出现卡死。退出设置界面,重启树莓派。
sudo raspi-config
增加交换空间以避免因内存问题导致的编译挂起
sudo nano /etc/dphys-swapfile
将 CONF_SWAPSIZE 值从默认值更改 100 为 1024
sudo /etc/init.d/dphys-swapfile restart
安装OpenCV所需的库 依次在终端输入以下命令进行安装
sudo apt-get install build-essential git cmake pkg-config -y
sudo apt-get install libjpeg8-dev -y
sudo apt-get install libtiff5-dev -y
sudo apt-get install libjasper-dev -y
sudo apt-get install libpng12-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt-get install libgtk2.0-dev -y
sudo apt-get install libatlas-base-dev gfortran -y
解压opencv压缩包
cd /home/pi/Downloads
unzip opencv-3.4.0.zip
unzip opencv_contrib-3.4.0.zip
拷包
cd /home/pi/Downloads/opencv_contrib-3.4.0/modules/xfeatures2d/src/
把缺失文件都拷过来
cp -r /home/pi/Downloads/opencv_contrib-3.4.0/modules/xfeatures2d/include/opencv2/xfeatures2d /home/pi/Downloads/opencv-3.4.0/modules/stitching/include/opencv2
cp -r /home/pi/Downloads/opencv_contrib-3.4.0/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp /home/pi/Downloads/opencv-3.4.0/modules/stitching/include/opencv2
vim /home/pi/Downloads/opencv-3.4.0/modules/python/src2/cv2.cpp
第885行把char* 改成 const char*
配置编译文件
cd /home/pi/Downloads/opencv-3.4.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/pi/Downloads/opencv_contrib-3.4.0/modules -D BUILD_EXAMPLES=ON -D WITH_LIBV4L=ON PYTHON3_EXECUTABLE=/usr/bin/python3.5 PYTHON_INCLUDE_DIR=/usr/include/python3.5 PYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.5m.so PYTHON3_NUMPY_INCLUDE_DIRS=/home/pi/.local/lib/python3.5/site-packages/numpy/core/include ..
编译,时间多达一个多个小时左右,在此此间做好树莓派散热,不要用 远程编译或者SSH编译
cd /home/pi/Downloads/opencv-3.4.0/build
sudo make -j4 2>&1 | tee make.log && sudo make install
测试是否成功安装
交换空间更改回原始大小,将 CONF_SWAPSIZE 值改回 100
sudo vim /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile restart
微信扫一扫,免费
保护
车主号码隐私
的挪车码
即可到手免费
使用