首页 > 代码库 > 用vs2010编译vigra静态库及简单使用举例

用vs2010编译vigra静态库及简单使用举例

1、  从 http://ukoethe.github.io/vigra/ 下载最新源代码vigra-1.10.0-src-with-docu.tar.gz,并加压缩到D:\soft\vigra,生成vigra-1.10.0文件夹;

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

3、  打开CMake,Where is thesource code: D:/soft/vigra/vigra-1.10.; Where to build the binaries: D:/soft/vigra/;

4、  点击Configure,-->Specify the generator for this project:Visual Studio 10, Use default nativecompilers, 点击finish;

5、  将VIGRA_STATIC_LIB勾选,点击Generate,如果有红色框出现,再次点击Generate即可;

6、  打开vs2010下的vigra.sln工程,首先选中vigraimpex工程,属性中的RuntimeLibrary,release下改为Multi-threaded(/MT),debug下改为Multi-threaded Debug(/MTd),然后分别在Debug和Release下选SolutionExplorer中的Solution ‘vigra’工程,点击右键,运行”Rebuild Solution”,会在D:\soft\vigra\vs2010\src\impex目录下生成Debug/vigraimpex.lib和/Release/vigraimpex.lib ;

7、新建一个控制台工程TestVigra, (1)、在debug下,将Code Generation下的Runtime Library改为Multi-threaded Debug(/MTd), 在release下,将Runtime Library 改为Multi-threaded(/MT) ;(2)、分别在debug和release下,在vc++ directories中,Include directories: D:\soft\vigra\vigra-1.10.0\include; (3)、分别在debug和release下,属性C/C++的Additional Include Directories:D:\soft\vigra\vigra-1.10.0\include; Preprocessor的Preprocessor Definitions: VIGRA_STATIC_LIB;(4)、属性中Character Set: Use Multi-Byte Character Set


stdafx.h:

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

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

using namespace vigra;

// TODO: reference additional headers your program requires here

stdafx.cpp:

// stdafx.cpp : source file that includes just the standard includes
// TestVigra.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

#ifdef _DEBUG
	#pragma comment(lib, "D:/soft/vigra/vs2010/src/impex/Debug/vigraimpex.lib")
#else
	#pragma comment(lib, "D:/soft/vigra/vs2010/src/impex/Release/vigraimpex.lib")
#endif

main.cpp:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[])
{
	try {
		cout<<"supported formats: "<<vigra::impexListFormats()<<endl;

		string strImageName = "base.bmp";
		string strOutImage  = "new.bmp";

		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;
	}

	cout<<"ok!"<<endl;

	return 0;
}