!!!重要参考文章:https://www.cnblogs.com/gghy/p/11916830.html
安装OpenCV的相关工具,gtk,等,GTK is a free and open-source cross-platform widget toolkit for creating graphical user interfaces. Create interfaces that users just love. Offering a complete set of UI elements, GTK is suitable for projects ranging from small one-off tools to complete application suites.
sudo apt install build-essential cmake git pkg-config libgtk-3-dev libcanberra-gtk*
安装视频I/O包
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev
安装安装OpenCV的图像工具包,优化函数包等
sudo apt install libjpeg-dev libpng-dev libtiff-dev gfortran libatlas-base-dev openexr opencl-headers
安装python开发相关,intel线程库tbb,Libdc1394 allows a program to interface with cameras that work on the ieee1394 ("firewire") standard. Libdc1394 is a library that is intended to provide a high level programming interface for application developers who wish to control IEEE 1394 based cameras that conform to the 1394-based Digital Camera Specification.
sudo apt install python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev
准备好源码包以及contribute的源码包,在opencv源码包下新建目录build_release,cd进入目录,执行以下cmake命令:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/pi/Documents/opencv_3.1.0_ALL/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=OFF ..
修改后:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D BUILD_TESTS=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/pi/Documents/opencv_3.1.0_ALL/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=OFF ..
接下来(选做操作)
sudo apt-get install gphoto2
sudo apt-get install libjasper-dev
接下来,21:00开始执行make -j4命令
make过程报错:fatal error: stdlib.h: 没有那个文件或目录
解决办法:-D ENABLE_PRECOMPILED_HEADERS=OFF,重新cmake,make
又报错(如下图所示):error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
解决办法:在/home/pi/Documents/opencv_3.1.0_ALL/opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp的头部添加:
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020
然后重新make,发现报错的部分顺利通过了。
经过越半个小时,进度100%,如下
这里,提示了“错误 2”,还不确定是否真正安装成够。
执行sudo make install,结果如下。发现相同错误提示,但都是python相关的,自己用不到python,因此暂时忽略该错误。
似乎仍然不能调用opencv,找不到opencv库,参考新的方法:http://www.waveshare.net/study/article-900-1.html
经实际测试,以上waveshare网站的方法完美可用。