1. 程式人生 > >SIFT特徵提取 應用篇

SIFT特徵提取 應用篇

               

SIFT特徵具有縮放、旋轉特徵不變性,下載了大牛的matlab版SIFT特徵提取程式碼,解釋如下:

1.呼叫方法:

將檔案加入matlab目錄後,在主程式中有兩種操作:

op1:尋找影象中的Sift特徵:

[image, descrips, locs] = sift('scene.pgm'); showkeys(image, locs);
op2:對兩幅圖中的SIFT特徵進行匹配:
match('scene.pgm','book.pgm');

由於scene和book兩圖中有相同的一本書,但orientation和size都不同,可以發現所得結果中Sift特徵檢測結果非常好。

2.程式碼下載地址:

3.想用自己的圖片進行呼叫:
i1=imread('D:\Images\New\Cars\image_0001.jpg');i2=imread('D:\Images\New\Cars\image_0076.jpg');i11=rgb2gray(i1);i22=rgb2gray(i2);imwrite(i11,'v1.jpg','quality',80);imwrite(i22,'v2.jpg','quality',80);match('v1.jpg','v2.jpg');
experiment results:
scene

book

compare_result

compare result

EXP2:

未找到匹配特徵的兩幅圖

C程式碼:

// 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()<<endlcout<<"size of description of Img2: "<<kp2.size()<<endlBFMatcher 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程式碼:

關於sift的其他講解:

關於computer vision的更多討論與交流,敬請關注本部落格和新浪微博Sophia_qing