SIFT特征提取-应用篇
2016-01-03 18:47
309 查看
SIFT特征具有缩放、旋转特征不变性,下载了大牛的matlab版SIFT特征提取代码,解释如下:
1.调用方法:
将文件加入matlab目录后,在主程序中有两种操作:
op1:寻找图像中的Sift特征:
[csharp] view
plaincopy
[image, descrips, locs] = sift('scene.pgm');
showkeys(image, locs);
op2:对两幅图中的SIFT特征进行匹配:
[csharp] view
plaincopy
match('scene.pgm','book.pgm');
由于scene和book两图中有相同的一本书,但orientation和size都不同,可以发现所得结果中Sift特征检测结果非常好。
2.代码下载地址:
book
compare result
EXP2:
C代码:
[cpp] view
plaincopy
// FeatureDetector.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include "vector"
#include "opencv\cxcore.hpp"
#include "iostream"
#include "opencv.hpp"
#include "nonfree.hpp"
#include "showhelper.h"
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//Load Image
Mat c_src1 = imread( "..\\Images\\3.jpg");
Mat c_src2 = imread("..\\Images\\4.jpg");
Mat src1 = imread( "..\\Images\\3.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat src2 = imread( "..\\Images\\4.jpg", CV_LOAD_IMAGE_GRAYSCALE);
if( !src1.data || !src2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//sift feature detect
SiftFeatureDetector detector;
std::vector<KeyPoint> kp1, kp2;
detector.detect( src1, kp1 );
detector.detect( src2, kp2 );
SiftDescriptorExtractor extractor;
Mat des1,des2;//descriptor
extractor.compute(src1,kp1,des1);
extractor.compute(src2,kp2,des2);
Mat res1,res2;
int drawmode = DrawMatchesFlags::DRAW_RICH_KEYPOINTS;
drawKeypoints(c_src1,kp1,res1,Scalar::all(-1),drawmode);//在内存中画出特征点
drawKeypoints(c_src2,kp2,res2,Scalar::all(-1),drawmode);
cout<<"size of description of Img1: "<<kp1.size()<<endl;
cout<<"size of description of Img2: "<<kp2.size()<<endl;
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(des1,des2,matches);
Mat img_match;
drawMatches(src1,kp1,src2,kp2,matches,img_match);//,Scalar::all(-1),Scalar::all(-1),vector<char>(),drawmode);
cout<<"number of matched points: "<<matches.size()<<endl;
imshow("matches",img_match);
cvWaitKey();
cvDestroyAllWindows();
return 0;
}
Python代码:
http://blog.csdn.net/abcjennifer/article/details/7639681
关于sift的其他讲解:
http://blog.csdn.net/abcjennifer/article/details/7639681
http://blog.csdn.net/abcjennifer/article/details/7372880
http://blog.csdn.net/abcjennifer/article/details/7365882
from: http://blog.csdn.net/abcjennifer/article/details/7365882
1.调用方法:
将文件加入matlab目录后,在主程序中有两种操作:
op1:寻找图像中的Sift特征:
[csharp] view
plaincopy
[image, descrips, locs] = sift('scene.pgm');
showkeys(image, locs);
op2:对两幅图中的SIFT特征进行匹配:
[csharp] view
plaincopy
match('scene.pgm','book.pgm');
由于scene和book两图中有相同的一本书,但orientation和size都不同,可以发现所得结果中Sift特征检测结果非常好。
2.代码下载地址:
<span style="vertical-align: baseline; color: rgb(19, 61, 182);"><a target=_blank target="_blank" href="http://www.cs.ubc.ca/~lowe/keypoints/" style="color: rgb(19, 61, 182); text-decoration: none; vertical-align: baseline;"><span style="font-family: 'Microsoft YaHei'; font-size: 13px;">http://www.cs.ubc.ca/~lowe/keypoints/</span></a></span>
<span style="font-family: 'Microsoft YaHei'; font-size: 13px;">3.想用自己的图片进行调用:</span>
<span style="font-family: 'Microsoft YaHei'; font-size: 13px;"></span><div class="dp-highlighter bg_csharp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; width: 878.5625px; overflow: auto; padding-top: 1px; margin: 18px 0px !important; background-color: rgb(231, 229, 220);"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(108, 226, 108); background-color: rgb(248, 248, 248);"><strong>[csharp]</strong> <a target=_blank href="http://blog.csdn.net/abcjennifer/article/details/7365882#" class="ViewSource" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">view plain</a><a target=_blank href="http://blog.csdn.net/abcjennifer/article/details/7365882#" class="CopyToClipboard" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">copy</a><a target=_blank href="https://code.csdn.net/snippets/135681" target="_blank" title="在CODE上查看代码片" style="color: rgb(160, 160, 160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; background-image: none; background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;"><img src="https://code.csdn.net/assets/CODE_ico.png" width="12" height="12" alt="在CODE上查看代码片" style="border: none; max-width: 100%; position: relative; top: 1px; left: 2px;" /></a><a target=_blank href="https://code.csdn.net/snippets/135681/fork" target="_blank" title="派生到我的代码片" style="color: rgb(160, 160, 160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; background-image: none; background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;"><img src="https://code.csdn.net/assets/ico_fork.svg" width="12" height="12" alt="派生到我的代码片" style="border: none; max-width: 100%; position: relative; top: 2px; left: 2px;" /></a><div style="position: absolute; left: 405px; top: 1050px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1" class="dp-c" style="padding: 0px; border: none; color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important; background-color: rgb(255, 255, 255);"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">i1=imread(</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'D:\Images\New\Cars\image_0001.jpg'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">i2=imread(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'D:\Images\New\Cars\image_0076.jpg'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">i11=rgb2gray(i1); </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">i22=rgb2gray(i2); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">imwrite(i11,<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'v1.jpg'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'quality'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,80); </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">imwrite(i22,<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'v2.jpg'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'quality'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,80); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">match(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'v1.jpg'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">'v2.jpg'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span></li></ol></div>
<span style="font-family: 'Microsoft YaHei'; font-size: 13px;">experiment results:</span>
<span style="font-family: 'Microsoft YaHei'; font-size: 13px;"><img src="http://hi.csdn.net/attachment/201203/18/0_1332039524thQs.gif" alt="" style="border: none; max-width: 100%;" /> </span>
<span style="font-family: 'Microsoft YaHei'; font-size: 13px;">scene</span>
book
compare result
EXP2:
C代码:
[cpp] view
plaincopy
// FeatureDetector.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include "vector"
#include "opencv\cxcore.hpp"
#include "iostream"
#include "opencv.hpp"
#include "nonfree.hpp"
#include "showhelper.h"
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//Load Image
Mat c_src1 = imread( "..\\Images\\3.jpg");
Mat c_src2 = imread("..\\Images\\4.jpg");
Mat src1 = imread( "..\\Images\\3.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat src2 = imread( "..\\Images\\4.jpg", CV_LOAD_IMAGE_GRAYSCALE);
if( !src1.data || !src2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//sift feature detect
SiftFeatureDetector detector;
std::vector<KeyPoint> kp1, kp2;
detector.detect( src1, kp1 );
detector.detect( src2, kp2 );
SiftDescriptorExtractor extractor;
Mat des1,des2;//descriptor
extractor.compute(src1,kp1,des1);
extractor.compute(src2,kp2,des2);
Mat res1,res2;
int drawmode = DrawMatchesFlags::DRAW_RICH_KEYPOINTS;
drawKeypoints(c_src1,kp1,res1,Scalar::all(-1),drawmode);//在内存中画出特征点
drawKeypoints(c_src2,kp2,res2,Scalar::all(-1),drawmode);
cout<<"size of description of Img1: "<<kp1.size()<<endl;
cout<<"size of description of Img2: "<<kp2.size()<<endl;
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(des1,des2,matches);
Mat img_match;
drawMatches(src1,kp1,src2,kp2,matches,img_match);//,Scalar::all(-1),Scalar::all(-1),vector<char>(),drawmode);
cout<<"number of matched points: "<<matches.size()<<endl;
imshow("matches",img_match);
cvWaitKey();
cvDestroyAllWindows();
return 0;
}
Python代码:
http://blog.csdn.net/abcjennifer/article/details/7639681
关于sift的其他讲解:
http://blog.csdn.net/abcjennifer/article/details/7639681
http://blog.csdn.net/abcjennifer/article/details/7372880
http://blog.csdn.net/abcjennifer/article/details/7365882
from: http://blog.csdn.net/abcjennifer/article/details/7365882
相关文章推荐
- android 代码实现控件之间的间距
- [Android]在代码里运行另一个程序的方法
- 肯特·贝克:改变人生的代码整理魔法
- 网页恶意代码的预防
- 高手写的Tracer-Flash代码调试类代码下载
- CSS代码缩写技巧
- 非主流Q-zOne代码代码搜集第1/2页
- CreateWeb.vbs 代码
- Lua中编译执行代码相关的函数详解
- 用于提取网易文件的hta代码
- 更有效率的css代码编写第1/3页
- 代码中到底应不应当写注释?
- SQL语言查询基础:连接查询 联合查询 代码
- 论坛头像随机变换代码
- 解析在main函数之前调用函数以及对设计的作用详解
- .NET 常用功能和代码小结
- C#实现压缩HTML代码的方法
- asp编程中常用的javascript辅助代码第1/2页
- C#超实用代码段合集
- Javascript代码在页面加载时的执行顺序介绍