vigra1.8.0的使用

来源:互联网 发布:java empty 编辑:程序博客网 时间:2024/06/16 03:55
 

VIGRA stands for "Vision with Generic Algorithms". It's a novel computer vision library that puts its main emphasis oncustomizablealgorithms and data structures.

1、首先,从http://hci.iwr.uni-heidelberg.de/vigra/下载最新源代码,并解压缩;

2、 从http://www.cmake.org/cmake/resources/software.html 下载cmake,并安装;

3、 打开cmake,在where is the source code中添加vigra源代码所在的位置,如:D:/soft/vigra/vigra-1.8.0-src/vigra-1.8.0;在where to build the binaries中添加编译后所存放的位置,如:D:/Program Files/vigra/vs2008。

4、 点击Configure,在弹出的对话框中选择Visual Studio 9 2008;如果有红色框显示,可根据实际情况进行修改,继续点击Configure;

点击Generate;会出现一个错误, CMake Error: Unknown Target referenced : doc_python,修改方法:打开D:/soft/vigra/vigra-1.8.0-src/vigra-1.8.0/ CMakeLists.txt,将其中的
 

IF(WITH_VIGRANUMPY)

     ADD_DEPENDENCIES(PACKAGE_SRC_TAR doc_python)

ENDIF()

替换为:

 IF(WITH_VIGRANUMPY AND PYTHON_SPHINX)

     ADD_DEPENDENCIES(PACKAGE_SRC_TAR doc_python)

ENDIF()

 

然后重新打开cmake,再重复上面步骤即可。
 

5、上述步骤完成之后,在vs2008文件夹中,就会看到有vigra.sln工程文件,打开此工程,分别在Debug和Release下编译整个工程,将会在vs2008/src/impex文件夹下生成Debug和Release的vigraimpex动态和静态库。

默认支持的图像格式包括:BMP、GIF、HDR、PNM、SUN、VIFF,若想支持更多种格式的图像,需要:源代码解压后会有一个” vigra-dependencies-win32-vs8.zip”压缩文件,将此文件解压到当前目录,会产生一个” dependencies”文件夹。在CMake中,在DDEPENDENCY_SEARCH_PREFIX中,将其value设为dependencies所在的目录即可。

此图像库的缺点是速度慢。

例子:

// TestVigra.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

 

#include <iostream>

#include <string>

 

#include "vigra/stdimage.hxx"

#include "vigra/impex.hxx"//Image import and export functions

#include "vigra/edgedetection.hxx"

 

using namespace vigra;

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

    try

    {

       cout<<"supported formats: "<<impexListFormats()<<endl;

 

       string strImageName = "E:\\vigra\\Image\\base.jpg";

       //string strImageName = "E:\\vigra\\Image\\basegray.jpg";

       string strOutImage  = "E:\\vigra\\Image\\new.jpg";

 

       ImageImportInfo info(strImageName.c_str(), 0);//read image

 

       //vigra_precondition(info.isGrayscale(), "Sorry, cannot operate on color images");

 

       double threshold=200, scale=0.5;

 

       if (info.isGrayscale())

       {

           BImage out(info.width(), info.height()); // create a gray scale image of appropriate size

           BImage in(info.width(), info.height());

 

           importImage(info, destImage(in));

          

           out = 255;// paint output image white

 

           importImage(info, destImage(out));// import the image just read

 

           //differenceOfExponentialEdgeImage(srcImageRange(in), destImage(out), scale, threshold, 0);

           //cannyEdgeImage(srcImageRange(in), destImage(out), scale, threshold, 0);// call edge detection algorithm

 

           transformImage(srcImageRange(in), destImage(out), linearIntensityTransform(-1, -255));//invert image

 

           exportImage(srcImageRange(out), ImageExportInfo(strOutImage.c_str()));// write the image to the file

       }

       else

       {

           BRGBImage out(info.width(), info.height());// create a RGB image of appropriate size

           BRGBImage in(info.width(), info.height());

 

           importImage(info, destImage(out));

           importImage(info, destImage(in));

 

           //RGBValue<int> offset(-255, -255, -255);

 

           //transformImage(srcImageRange(in), destImage(out), linearIntensityTransform(-1, offset));

 

           double sizefactor = 1.2;

           int nw = (int)(sizefactor*(info.width()-1) + 1.5); // calculate new image size

           int nh = (int)(sizefactor*(info.height()-1) + 1.5);

 

           BRGBImage out1(nw, nh);

 

           resizeImageSplineInterpolation(srcImageRange(in), destImageRange(out1));// resize the image, using a bi-cubic spline algorithms

 

           exportImage(srcImageRange(out1), ImageExportInfo(strOutImage.c_str()));

       }

    }

    catch (StdException &e)

    {

       cout<<e.what()<<endl;// catch any errors that might have occurred and print their reason

       return 1;

    }

 

    return 0;

}

原创粉丝点击