步骤1.安装依赖项
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
可选的
sudo apt-get install checkinstall yasm libtiff5-dev libjpeg-dev libjasper-dev libdc1394-22-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils libeigen3-dev
步骤#2:下载OpenCV源代码
为了方便,我已经包含了opencv归档文件的完整URL以及下面的opencv_contrib归档文件:
- https://github.com/Itseez/opencv/archive/3.1.0.zip
- https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
步骤3.生成cmake编译配置
这里下载文件可能会出错,解决办法就是去官网下载ippicv_linux_20151201.tgz,然后放到该路径下
下载 ippicv_linux_20151201
/home/computer/opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ 没有的文件夹要新建
创建编译目录
1 cd opencv-3.1.0 2 mkdir release 3 cd release
编译opencv及opencv_contrib
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/opencv/opencv_contrib/modules/ .. 如果不安装opencv_contrib模块,则第二步的命令为: cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local
CMAKE_INSTALL_PREFIX为你的opencv安装路径,OPENCV_EXTRA_MODULES_PATH是你的opencv_contrib/modules/的路径,可以参照在我的电脑上为
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-3.1.0 -D OPENCV_EXTRA_MODULES_PATH=/home/zn/opencv-3.1.0/opencv_contrib-3.1.0/modules/ ..
4.安装
make
sudo make install
make的时候大概会出现报错,参考以下链接解决
https://github.com/opencv/opencv/issues/6016
5.测试
查看opencv版本
pkg-config --modversion opencv
在我的电脑上大概编译20分钟就可以完成了