opencv3.X版本的编译和之前有些区别,它将一些不稳定或者说在开发中的模块都放到contrib modules里面了,用户视自己的需求去编译.这篇文章记录了Ubuntu14.04 + opencv3.2.0 + contrib modules 的配置方法,供自己记录和大家参考一下.谢谢
1 opencv依赖项安装
sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev这些依赖项有些机器上可能已经装好了,但是以防万一,可以再做一遍.
2 opencv源码下载
源码的下载有两种方式:去官网下载压缩包再解压,或者直接git拉取源码
3 编译以及安装
mkdir ~/opencv320 cd ~/opencv320第2步里面下载的应该是两个包:opencv-master和opencv_contrib-master,
将contrib模块拷贝到opencv-master文件夹下
cp -r opencv_contrib-master opencv-master
cd opencv-master
mkdir build
cd build
开始cmake
原文链接:/ubuntu/352697.htmlcmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules/ ..cmake完成之后(确认complete,没有error),make -j7sudo make install完成安装4 测试安装结果
1) 创建工作目录
mkdir ~/opencv-lena cd ~/opencv-lena gedit DisplayImage.cpp2) 编写如下代码
#include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; int main(int argc,char** argv ) { if ( argc != 2 ) { printf("usage: DisplayImage.out <Image_Path>\n"); return -1; } Mat image; image = imread( argv[1], ); if ( !image.data ) { printf(No image data \n; } namedWindow(Display Image,WINDOW_AUTOSIZE ); imshow( waitKey(0); return ; }3) 创建CMake编译文件gedit CMakeLists.txt写入如下内容
cmake_minimum_required(VERSION 2.8) project( DisplayImage ) find_package( OpenCV required ) add_executable( DisplayImage DisplayImage.cpp ) target_link_libraries( DisplayImage ${OpenCV_LIBS} )4) 编译cd ~/opencv-lena cmake . make5) 执行此时opencv-lena文件夹中已经产生了可执行文件DisplayImage,下载lena.jpg放在opencv-lena下,运行
./DispalyImage lena.jpg
至此,安装配置完成.