用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 sizeBImage in(info.width(), info.height());importImage(info, destImage(in));out = 255;// paint output image whiteimportImage(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 algorithmtransformImage(srcImageRange(in), destImage(out), linearIntensityTransform(-1, -255));//invert imageexportImage(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 sizeBRGBImage 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 sizeint 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 algorithmsexportImage(srcImageRange(out1), ImageExportInfo(strOutImage.c_str()));}} catch (StdException &e) {cout<<e.what()<<endl;// catch any errors that might have occurred and print their reasonreturn 1;}cout<<"ok!"<<endl;return 0;
}
GitHub:https://github.com/fengbingchun/Vigra_Test
?
?
?
總結
以上是生活随笔為你收集整理的用vs2010编译vigra静态库及简单使用举例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Neon Intrinsics各函数介绍
- 下一篇: Android.mk和Applicati