ubuntu下codeblock安装与opencv配置

最近在用OpenCV做东西,之前写了一篇在Windows下配置CodeBlocks+OpenCV2.0的文章。昨天心血来潮装了一个Ubuntu,于是也把CodeBlocks装上了,又装上了OpenCV,在Linux下面也搭了个平台。安装过程如下:

一、CodeBlocks的安装

1》安装基本编译环境
代码:
sudo apt-get install build-essential
sudo apt-get install gdb

2》安装codeblock
代码:
sudo apt-get install codeblocks
sudo apt-get install codeblocks-dbg
sudo apt-get install wxformbuilder
还有个codeblocks-contrib其实安装的是wxSmith,我还是喜欢wxfb,所以就没有安装。

3》安装wxWidgets
代码:
sudo apt-get install libwxbase2.8
sudo apt-get install libwxbase2.8-dev
sudo apt-get install libwxgtk2.8-0
sudo apt-get install libwxgtk2.8-dev
sudo apt-get install libwxgtk2.8-dbg
sudo apt-get install wx-common
sudo apt-get install wx2.8-headers
sudo apt-get install wx2.8-i18n
还有wx2.8-examples和wx2.8-doc想看文档的可以装上

4》配置codeblock
打开codeblock
settings->global variables
current variable标签后面点击new按钮,出来的框框里填写wx。
然后builtin fields下面
base /usr
include /usr/include/wx-2.8
lib /usr/lib
然后点击close就保存设置了。这里我设置完了以后新建gui工程做了一个简单的helloworld对话框。却提示找不.h文件。于是狂晕,在 google上满世界找。耽误了一个多小时也没结果。后来一怒之下关掉codeblock。当我不死心再打开后,所有文件顺利编译通过。

二、OpenCV的安装

打开codeblocks

点击最上面的setting->complierand debugger,选择linkersetting。在Linklibraries下面选择添加:

/usr/local/lib/libopencv_calib3d.so

/usr/local/lib/libopencv_contrib.so

/usr/local/lib/libopencv_core.so

/usr/local/lib/libopencv_features2d.so

/usr/local/lib/libopencv_flann.so

/usr/local/lib/libopencv_gpu.so

/usr/local/lib/libopencv_highgui.so

/usr/local/lib/libopencv_imgproc.so

/usr/local/lib/libopencv_legacy.so

/usr/local/lib/libopencv_ml.so

/usr/local/lib/libopencv_objetdect.so

/usr/local/lib/libopencv_ts.so

/usr/local/lib/libopencv_video.so

然后选择searchdirectory->compiler,在里面加入

/usr/local/include/

/usr/local/include/opencv

/usr/local/include/opencv2

然后选择,searchdirectory下面的linker选线,添加

/usr/local/lib

最后,输入源代码测试:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    const char* imagename = "emosue.jpg";

    //从文件中读入图像
    Mat img = imread(imagename);

    //如果读入图像失败
    if(img.empty())
    {
        cout<<"Error Image Name!!!"<<endl;
        return -1;
    }

    //显示图像
    imshow("image", img);

    //此函数等待按键,按键盘任意键就返回
    waitKey();

    return 0;
}


图解如下:

2、  codeBlocks链接库配置: Project -> Build Options 如下图:

 

ubuntu下codeblock安装与opencv配置_第1张图片

3、   codeBlocks 头文件目录配置(pkg-config --cflags opencv   结果)

 

ubuntu下codeblock安装与opencv配置_第2张图片

4、  CodeBlocks 路文件目录配置

 

ubuntu下codeblock安装与opencv配置_第3张图片


你可能感兴趣的:(ubuntu下codeblock安装与opencv配置)