树莓派4B安装OPENCV4.0
参考 : https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/
Step #1: Expand filesystem on your Raspberry Pi
sudo raspi-config
重启
Step #2:Install OpenCV 4 dependencies on your Raspberry Pi
sudo apt update
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libcanberra-gtk*
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3-dev
Step #3: Download OpenCV 4 for your Raspberry Pi
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
mv opencv-4.0.0 opencv
mv opencv_contrib-4.0.0 opencv_contrib
cd ~/opencv
mkdir build
cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/lib \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..
sudo nano /etc/dphys-swapfile
# CONF_SWAPSIZE=100
CONF_SWAPSIZE=2048
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
make -j4
sudo make install
sudo ldconfig
~/opencv_contrib/modules/xfeatures2d/src/boostdesc.cpp:673:20: fatal error: boostdesc_bgm.i: No such file or directory
解决方式:
采用的是源码编译的方式,所以可以查看 build 文件夹下的日志文件 CMakeDownloadLog.txt,在日志文件CMakeDownloadLog.txt中搜索 boostdesc_bgm.i 关键词 (不是在文件夹中搜索),
发现这个文件下载失败了。日志文件里就有它的下载地址,直接复制其下载地址到网页可以看该到文件的源码,直接拷贝源码并生存同名文件,放在 opencv_contrib/modules/xfeatures2d/src/ 路径下即可。
总共缺了以下几个文件,都需要拷贝:
boostdesc_bgm.i
boostdesc_bgm_bi.i
boostdesc_bgm_hd.i
boostdesc_lbgm.i
boostdesc_binboost_064.i
boostdesc_binboost_128.i
boostdesc_binboost_256.i
vgg_generated_120.i
vgg_generated_64.i
vgg_generated_80.i
vgg_generated_48.i
sudo nano /etc/dphys-swapfile
CONF_SWAPSIZE=100
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
最后,opencv安装在/usr/lib下,在该目录下,会生成一个python的文件夹。
我的python也在安装在/usr/lib文件夹下,分别是python2.7,python3,python3.7。默认改为了python3.7。
将python目录下的/cv2/python-3.7/cv2.cpython-37m-arm-linux-gnueabihf.so拷贝到/usr/lib/python3.7下,也就是python的安装路径。