安装编译工具
apt-get install build-essential
安装依赖包
apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
# vi /etc/resolv.conf
/etc/init.d/networking restart
#apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
报错:
解决方法:
不使用阿里云开源镜像站,换一个开源镜像站
再次安装依赖包
#apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
成功解决:
apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
下载源码
打开https://opencv.org/releases.html,或者https://github.com/opencv/opencv/releases,下载opencv-3.4.1.zip,下载完毕通过共享文件,将opencv-3.4.1共享到Ubuntu上。
工作目录准备
#mkdir /opt/wkspace/opencv
#cd /opt/wkspace/opencv
将上面两个目录下共享到opencv目录下
解压进入源码包
#unzip opencv_contrib-3.4.1.zip
#unzip opencv-3.4.1.zip
#cd opencv-3.4.1
#mkdir build
#cd build
配置运行cmake
#cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.1/modules/..
报错:
#cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.1/modules/ ..
Modules后面要加个空格modules/ …
编译安装
#make
报错:
这一类问题解决方法:
继续编译make
报错:
解决方法:
/opt/wkspace/opencv/opencv-3.4.1/modules/stitching/include/opencv2/stitching/detail/matchers.hpp中的第52行 include“opencv2/xfeatures2d/cuda.hpp”
改成cuda.hpp所在的路径/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2/xfeatures2d
即改为:include”/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp”
继续编译make
报错:
解决方法:
如上操作,将include中包含的头文件改为include”/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp”
再编译make
报错:
解决方法:找到xfeatures2d.hpp的路径为/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2
将报错的52行处改为include”/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp”
解决方法:找到文件nonfree.hpp的路径为/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2/xfeatures2d
修改报错的第43行,改为:
include”/opt/wkspace/opencv/opencv_contrib-3.4.1/modules/xfeatures2d/include/opencv2/xfeatures2d/nonfree.hpp”
再编译make
成功!!!
#make install
经过一段时间的等待,opencv编译完成
安装成功后需要将opencv的库加入到系统路径中,从而让系统可以找到。
#vi /etc/ld.so.conf.d/opencv.conf
打开后可能是个空白的文件,不用管,只需要在文件末尾添加
/usr/local/lib
有效编译环境
#ldconfig
#vi /etc/bash.bashrc
在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
执行
#source /etc/bash.bashrc
更新
#updatedb
时间有点长,更新数据文件
本地测试(前提:已插入免驱的usb摄像头)
#cd opencv-3.4.1/samples/cpp/example_cmake
#cmake
#make
#./opencv_example