<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0065)http://www.cnblogs.com/freedomshe/archive/2012/04/28/2475057.html -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK
href="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/common.css" type=text/css
rel=stylesheet><LINK id=MainCss
href="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/style.css" type=text/css
rel=stylesheet><LINK
href="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/common2.css" type=text/css
rel=stylesheet><LINK
href="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/shStyle.css" type=text/css
rel=stylesheet><LINK title=RSS href="http://www.cnblogs.com/freedomshe/rss"
type=application/rss+xml rel=alternate><LINK title=RSD
href="http://www.cnblogs.com/freedomshe/rsd.xml" type=application/rsd+xml
rel=EditURI><LINK href="http://www.cnblogs.com/freedomshe/wlwmanifest.xml"
type=application/wlwmanifest+xml rel=wlwmanifest>
<SCRIPT src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/jquery.js"
type=text/javascript></SCRIPT>
<SCRIPT type=text/javascript>
var currentBlogApp = 'freedomshe';
</SCRIPT>
<SCRIPT src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/common.js"
type=text/javascript></SCRIPT>
<SCRIPT src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/json2.js"
type=text/javascript></SCRIPT>
<SCRIPT src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/syntaxHighlighter.js"
type=text/javascript></SCRIPT>
<META content="MSHTML 6.00.2900.6287" name=GENERATOR></HEAD>
<BODY><A name=top></A><!--done-->
<DIV id=home>
<DIV id=header>
<DIV id=blogTitle><A id=lnkBlogLogo
href="http://www.cnblogs.com/freedomshe/"><IMG id=blogLogo alt=返回主页
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/logo.gif"></A> <!--done-->
<H1><A class=headermaintitle id=Header1_HeaderTitle
href="http://www.cnblogs.com/freedomshe/">FreedomShe</A></H1>
<H2>Yuanbo She's BLOG</H2></DIV><!--end: blogTitle 博客的标题和副标题 -->
<DIV id=navigator>
<UL id=navList>
<LI><A class=menu id=MyLinks1_HomeLink href="http://www.cnblogs.com/">博客园</A>
</LI>
<LI><A class=menu id=MyLinks1_MyHomeLink
href="http://www.cnblogs.com/freedomshe/">首页</A> </LI>
<LI><A href="http://news.cnblogs.com/">新闻</A> </LI>
<LI><A class=menu id=MyLinks1_NewPostLink
href="http://www.cnblogs.com/freedomshe/admin/EditPosts.aspx?opt=1"
rel=nofollow>新随笔</A> </LI>
<LI><A class=menu id=MyLinks1_ContactLink accessKey=9
href="http://space.cnblogs.com/msg/send/FreedomShe" rel=nofollow>联系</A> </LI>
<LI><A class=menu id=MyLinks1_Admin
href="http://www.cnblogs.com/freedomshe/admin/EditPosts.aspx"
rel=nofollow>管理</A> </LI>
<LI><A class=menu id=MyLinks1_Syndication
href="http://www.cnblogs.com/freedomshe/rss">订阅</A> <A class=aHeaderXML
id=MyLinks1_XMLLink href="http://www.cnblogs.com/freedomshe/rss"><IMG alt=订阅
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/rss.gif"></A> </LI></UL>
<DIV class=blogStats><!--done-->随笔- 6 文章- 1 评论- 18 </DIV><!--end: blogStats --></DIV><!--end: navigator 博客导航栏 --></DIV><!--end: header 头部 -->
<DIV id=main>
<DIV id=mainContent>
<DIV class=forFlow><!--done-->
<DIV id=topics>
<DIV class=post>
<H1 class=postTitle><A class=postTitle2 id=cb_post_title_url
href="http://www.cnblogs.com/freedomshe/archive/2012/04/28/2475057.html">在VS2010中应用SIFT(C)源码</A>
</H1>
<DIV class=clear></DIV>
<DIV class=postBody>
<DIV id=cnblogs_post_body>
<P>SIFT的实现有很多版本,具体方式都是那么几个,找个好用的不太容易,因为对于代码不熟练者各种版本用起来都有点水土不服,需要调整调整才行。本人是在VS2010下使用的Rob
Hess的源码。</P>
<H1>一、前提</H1>
<P>安装Opencv,详见:<A class=postTitle2 id=cb_post_title_url
href="http://www.cnblogs.com/freedomshe/archive/2012/04/25/2470540.html"
target=_blank>VS2010+Opencv-2.4.0的配置攻略</A>(该版本SIFT是基于Opencv的)。</P>
<P>下载SIFT源码,见<SPAN><A title="Rob Hess" href="http://blogs.oregonstate.edu/hess/"
rel=home>Rob Hess</A></SPAN>的主页(别告诉我不懂英文不知道下载链接在哪,下那个Windows VC++的版本
sift-latest_win.zip)。</P>
<H1>二、测试</H1>
<P>1、解压sift源码,发现有如下文件:</P>
<P><IMG alt=""
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/2012042814591324.png"></P>
<P>其中有3个是解决方案文件夹:siftFeat、match和dspFeat,siftFeat工程是做SITF特征提取的,一般只会用到这个案例,match是利用SIFT特征做图像匹配的,desFeat没用过不说了。</P>
<P>所有源代码(包括上面3个工程的main)都在文件夹外面,就是那些成对的.h和.c了。</P>
<P>2、可以先试着跑跑siftFeat。</P>
<P>打开siftFeat.sln,配置好Opencv在VS2010中的环境参数(<A class=postTitle2
id=cb_post_title_url
href="http://www.cnblogs.com/freedomshe/archive/2012/04/25/2470540.html"
target=_blank>VS2010+Opencv-2.4.0的配置攻略</A>中有述,注意include里面要添加/include/opencv,因为sift源码直接引用了/include/opencv目录下的头文件)。</P>
<P>编译报错:<BR><SPAN style="COLOR: #0000ff">1>utils.obj : error LNK2001:
无法解析的外部符号 _va_end</SPAN><BR><SPAN style="COLOR: #0000ff">1>utils.obj : error
LNK2001: 无法解析的外部符号 _va_start</SPAN></P>
<P>说好了源码里面有些东西是要改的:在utils.c中<SPAN style="COLOR: #0000ff">#include
<stdarg.h></SPAN>就OK了。</P>
<P>F5调试运行,成功显示:</P>
<P><IMG alt=""
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/2012042815335069.png"></P>
<H1>三、在C++工程中应用SIFT</H1>
<P>1、在VS2010中新建自己的C++工程PP。在工程根目录内添加目录命名为sift,将sift源码文件imgfeatures.c
imgfeatures.h kdtree.c kdtree.h minpq.c minpq.h sift.c sift.h utils.c utils.h
xform.c xform.h(即除了match.c siftfeat.c dspfeat.c的所有源码文件)复制到\PP\sift内。</P>
<P><IMG alt=""
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/2012042815582988.png"></P>
<P>2、在VS2010内引入sift源码:在“资源管理器”视图里添加“筛选器”,命名为sift,将刚才拷贝过来的sift源文件引入其内:</P>
<P><IMG alt=""
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/2012042816040384.png"></P>
<P>3、在需要使用sift方法的地方添加对应头文件:</P>
<DIV class=cnblogs_code><PRE>#include <SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">..\sift\sift.h</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">
#include </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">..\sift\imgfeatures.h</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">
#include </SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">..\sift\utils.h</SPAN><SPAN style="COLOR: #800000">"</SPAN></PRE></DIV>
<P> 4、取消.c文件的预编译:同样在“资源管理器”视图下面复选sift文件夹内所有.c文件,右键选择“属性”,选取“C/C++”->“预编译头”,在“预编译头”选项中选择“不使用预编译头”。</P>
<P><IMG alt=""
src="在VS2010中应用SIFT(C)源码 - FreedomShe - 博客园.files/20120428161