码迷,mamicode.com
首页 > 编程语言 > 详细

OpenCv sift算法 图像特征匹配

时间:2016-08-19 11:12:15      阅读:909      评论:0      收藏:0      [点我收藏+]

标签:

基于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 }
Sift

技术分享   技术分享 

                 Lena                                             Lena2

 

 技术分享

                                          Duang~

 

OpenCv sift算法 图像特征匹配

标签:

原文地址:http://www.cnblogs.com/gaohai/p/5786714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!