SIFT特征提取-应用篇

来源:互联网 发布:2016网络春晚 编辑:程序博客网 时间:2024/04/30 05:10

SIFT特征具有缩放、旋转特征不变性,下载了大牛的matlab版SIFT特征提取代码,解释如下:

1.调用方法:

将文件加入matlab目录后,在主程序中有两种操作:

op1:寻找图像中的Sift特征:

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. [image, descrips, locs] = sift('scene.pgm');   
  2. showkeys(image, locs);  

op2:对两幅图中的SIFT特征进行匹配:

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. 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; background-color: rgb(231, 229, 220); width: 936.71875px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(108, 226, 108);"><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; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-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; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-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; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-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; background-image: none; background-color: inherit; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; background-position: 0% 0%; background-repeat: no-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: 398px; top: 928px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1" class="dp-c" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><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: 17.27272605895996px; 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; background-color: rgb(248, 248, 248); line-height: 17.27272605895996px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><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: 17.27272605895996px; 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; background-color: rgb(248, 248, 248); line-height: 17.27272605895996px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><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: 17.27272605895996px; 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; background-color: rgb(248, 248, 248); line-height: 17.27272605895996px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><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: 17.27272605895996px; 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

compare result

EXP2:

未找到匹配特征的两幅图



C代码:

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. // FeatureDetector.cpp : Defines the entry point for the console application.  
  2. //  
  3.   
  4. #include "stdafx.h"  
  5. #include "highgui.h"  
  6. #include "cv.h"  
  7. #include "vector"  
  8. #include "opencv\cxcore.hpp"  
  9. #include "iostream"  
  10. #include "opencv.hpp"  
  11. #include "nonfree.hpp"  
  12. #include "showhelper.h"  
  13.   
  14. using namespace cv;  
  15. using namespace std;  
  16.   
  17. int _tmain(int argc, _TCHAR* argv[])  
  18. {  
  19.     //Load Image   
  20.     Mat c_src1 =  imread( "..\\Images\\3.jpg");  
  21.     Mat c_src2 = imread("..\\Images\\4.jpg");  
  22.     Mat src1 = imread( "..\\Images\\3.jpg", CV_LOAD_IMAGE_GRAYSCALE);  
  23.     Mat src2 = imread( "..\\Images\\4.jpg", CV_LOAD_IMAGE_GRAYSCALE);  
  24.     if( !src1.data || !src2.data )  
  25.     { std::cout<< " --(!) Error reading images " << std::endl; return -1; }  
  26.   
  27.     //sift feature detect  
  28.     SiftFeatureDetector detector;  
  29.     std::vector<KeyPoint> kp1, kp2;  
  30.   
  31.     detector.detect( src1, kp1 );  
  32.     detector.detect( src2, kp2 );  
  33.     SiftDescriptorExtractor extractor;  
  34.     Mat des1,des2;//descriptor  
  35.     extractor.compute(src1,kp1,des1);  
  36.     extractor.compute(src2,kp2,des2);     
  37.     Mat res1,res2;   
  38.     int drawmode = DrawMatchesFlags::DRAW_RICH_KEYPOINTS;  
  39.     drawKeypoints(c_src1,kp1,res1,Scalar::all(-1),drawmode);//在内存中画出特征点  
  40.     drawKeypoints(c_src2,kp2,res2,Scalar::all(-1),drawmode);  
  41.     cout<<"size of description of Img1: "<<kp1.size()<<endl;  
  42.     cout<<"size of description of Img2: "<<kp2.size()<<endl;  
  43.   
  44.     BFMatcher matcher(NORM_L2);  
  45.     vector<DMatch> matches;  
  46.     matcher.match(des1,des2,matches);  
  47.     Mat img_match;  
  48.     drawMatches(src1,kp1,src2,kp2,matches,img_match);//,Scalar::all(-1),Scalar::all(-1),vector<char>(),drawmode);  
  49.     cout<<"number of matched points: "<<matches.size()<<endl;  
  50.     imshow("matches",img_match);  
  51.     cvWaitKey();  
  52.     cvDestroyAllWindows();  
  53.   
  54.     return 0;  
  55. }  


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


0 0
原创粉丝点击