ubuntu15.10 配置opencv开发环境

1、去官网下载最新的opencv版本

下载Linux的即可
http://opencv.org/downloads.html

2、安装必要的依赖包等

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

3、解压,在该目录下使用cmake命令

解压压缩包,然后在控制台下,进入该目录输入

cmake .

. 不可缺少,作为cmake 的参数

注意,在这个过程中,需要下载一个包ippicv_linux_20151201.tgz,但是它自己下载的包检验哈希值的时候却会出错,解决方法去直接去下载(百度就行),然后在目录下替换即可:
/home/xiaojian/programming/opencv-3.1.0/3rdparty/ippicv/downloads

4、输入make 和 sudo make install

依次输入以下命令:

make
sudo make install

5、配置library

打开 /etc//ld.so.conf.d/opencv.conf,在末尾加入/usr/local/lib
有可能需要新建文件,不过没有关系
然后输入命令:

sudo ldconfig

然后编辑/etc/bash.bashrc
文件末尾加入:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

6、测试:

查看opencv 的环境参数:
依次输入:

 pkg-config --cflags opencv  
 pkg-config --libs opencv 

即可看到相关参数

然后,新建一个文件测试一下:

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
    Mat image;
    image = imread("img/lena.jpg", 1);
    if(!image.data)
    {
        cout<<"error!"<<endl;
        return -1;
    }
    namedWindow("Lena.jpg", WINDOW_AUTOSIZE);
    imshow("Lena.jpg", image);
    waitKey(0);
}

然后图片你要自己写好参数

7、编译与makeFile

一般来说,命令行下直接编译即可:

g++ `pkg-config --cflags opencv` -o test test.cpp `pkg-config --libs opencv`  

但是我不知道为什么,它老是提示我找不到 lippicv的库。
那我只能换一下方式,现在我也不知道这个库是干嘛的,先不要它先。
在上一步中,我查看库有命令如下:

-L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lippicv -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core

其中就有-lippicv 我把上面复制下来,去掉前面的路径和这个库,变成下面的方式:

g++ `pkg-config --cflags opencv` -o test test.cpp -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab  -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core

看起来确实很烦,但好歹编译通过了。

下面贴一下我的makefile命令,以备以后使用:

objects = ReadCfg.o main.o
clibs = `pkg-config opencv --cflags opencv`
SIFT: $(objects)
    g++ $(clibs) $(objects) -o SIFT -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab  -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core 
main.o: main.cpp
    g++ $(clibs) -c main.cpp -std=c++11  -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab  -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann  -lopencv_core
ReadCfg.o: ReadCfg.cpp ReadCfg.h
    g++ -c ReadCfg.cpp -std=c++11


clean:
    rm *.o

参考资料:
ubuntu14.04+opencv 3.0+python2.7安装及测试
opencv在ubuntu下的安装
fedora23下编译安装OpenCV-3.1.0

(最后,如果谁有解决ippicv库的问题,麻烦教一下我~)

–END–

你可能感兴趣的:(linux,ubuntu,opencv)