基于OpenCv 2.4.6
1 #include "highgui.h" 2 3 //#include "features2d/features2d.hpp"// 4 #include <opencv2/nonfree/features2d.hpp> 5 #include<opencv2/legacy/legacy.hpp> 6 #include <iostream> 7 using namespace std; 8 using namespace cv; 9 10 void main(int argc, char** argv[]) 11 { 12 Mat input1=imread("Lena.jpg",1); 13 Mat input2=imread("Lena2.jpg",1); 14 SiftFeatureDetector detector; 15 vector<KeyPoint> keypoint1,keypoint2; 16 detector.detect(input1,keypoint1); 17 18 Mat output1; 19 drawKeypoints(input1,keypoint1,output1); 20 imshow("sift_result1.bmp",output1); 21 imwrite("sift_result1.bmp",output1); 22 23 Mat output2; 24 SiftDescriptorExtractor extractor; 25 Mat descriptor1,descriptor2; 26 BruteForceMatcher<L2<float>> matcher; 27 28 vector<DMatch> matches; 29 Mat img_matches; 30 detector.detect(input2,keypoint2); 31 drawKeypoints(input2,keypoint2,output2); 32 33 imshow("sift_result2.bmp",output2); 34 imwrite("sift_result2.bmp",output2); 35 36 extractor.compute(input1,keypoint1,descriptor1); 37 extractor.compute(input2,keypoint2,descriptor2); 38 39 matcher.match(descriptor1,descriptor2,matches); 40 41 drawMatches(input1,keypoint1,input2,keypoint2,matches,img_matches); 42 imshow("matches",img_matches); 43 imwrite("matches.jpg",img_matches); 44 45 waitKey(); 46 47 48 }
Lena Lena2
Duang~