学习OpenCV——Fast检测与Surf&Brief匹配(娱乐)

http://blog.csdn.net/sangni007/article/details/7547350

这几天一直徘徊在Fast,Surf,Shift,Brief,ORB几种特征检测算法之中,被搞得焦头烂额!!!

各个实验都在前面的blog中。

OpenCV已经实现了他们,所以就用OpenCV试验一下,各种方法,查看一下效果,

我的初衷是Match,Fast检测的特征点,发现无法提取descriptor,⊙﹏⊙b汗!!!

但是,却又发现可以将Keypoints检测与Match的过程分开(虽然知道这也许没啥意思,也就试试)

1.Fast检测特征点:FastFeatureDetector fast2(40);//阈值=40   

                            fast1.detect(src1,keys1);//检测特征点

 

2.Match:两种方法

   2.1:Surf描述:SurfDescriptorExtractor Extractor;

                           Mat descriptors1,descriptors2;

                           Extractor.compute(src1,keys1,descriptors1);

                           Extractor.compute(src2,keys2,descriptors2);

                                           

                                             FlannBasedMatcher matcher;或者BruteForceMatcher< L2<float> > matcher;

                           FlannBasedMatcher matcher;
                           vector< DMatch > matches;  
                           matcher.match( descriptors1, descriptors2, matches ); 

    2.2:Brief描述:BriefDescriptorExtractor Extractor;

                          +BruteForceMatcher< Hamming > matcher;

3.drawMatches;

(其他的方法ORB等,提取特征和描述是直接一步操作完成的,无法把Fast特征点带入计算。这也就是一种无心的玩闹,看看了了)

 

  1. #include <opencv2/core/core.hpp>     
  2. #include <opencv2/features2d/features2d.hpp>     
  3. #include <opencv2/highgui/highgui.hpp>  
  4.   
  5. #include <vector>  
  6. #include <iostream>  
  7. using namespace cv;  
  8. using namespace std;  
  9.   
  10. char img_filename1[]="D:/src.jpg";  
  11. char img_filename2[]="D:/Demo.jpg";  
  12.   
  13. void main()  
  14. {  
  15.     Mat src1,src2;  
  16.     src1 = imread(img_filename1,1);  
  17.     src2 = imread(img_filename2,1);  
  18.     // vector of keyPoints  
  19.     vector<KeyPoint> keys1;  
  20.     vector<KeyPoint> keys2;  
  21.     // construction of the fast feature detector object  
  22.     FastFeatureDetector fast1(40);  // 检测的阈值为40  
  23.     FastFeatureDetector fast2(40);  
  24.     // feature point detection  
  25.     fast1.detect(src1,keys1);  
  26.     double t;  
  27.     t=getTickCount();  
  28.     fast2.detect(src2,keys2);  
  29.     t=getTickCount()-t;  
  30.     t=t*1000/getTickFrequency();  
  31.     cout<<"KeyPoint Size:"<<keys2.size()<<endl;  
  32.     cout<<"extract time:"<<t<<"ms"<<endl;  
  33.     drawKeypoints(src1, keys1, src1, Scalar::all(-1), DrawMatchesFlags::DRAW_OVER_OUTIMG);  
  34.     drawKeypoints(src2, keys2, src2, Scalar::all(-1), DrawMatchesFlags::DRAW_OVER_OUTIMG);  
  35.     imshow("FAST feature1", src1);  
  36.     imshow("FAST feature2", src2);  
  37.     cvWaitKey(0);  
  38.     t=getTickCount();  
  39.       
  40.     SurfDescriptorExtractor Extractor;//Run:BruteForceMatcher< L2<float> > matcher  
  41.     //ORB Extractor;//Not Run;  
  42.     //BriefDescriptorExtractor Extractor;//RUN:BruteForceMatcher< Hamming > matcher  
  43.     Mat descriptors1, descriptors2;  
  44.     Extractor.compute(src1,keys1,descriptors1);  
  45.     Extractor.compute(src2,keys2,descriptors2);  
  46.   
  47.     //BruteForceMatcher< Hamming > matcher;  
  48.     //BruteForceMatcher< L2<float> > matcher;  
  49.     FlannBasedMatcher matcher;  
  50.     vector< DMatch > matches;    
  51.     matcher.match( descriptors1, descriptors2, matches );    
  52.     t=getTickCount()-t;  
  53.     t=t*1000/getTickFrequency();  
  54.     cout<<"match time:"<<t<<"ms"<<endl;  
  55.      Mat img_matches;    
  56.      drawMatches( src1, keys1, src2, keys2, matches, img_matches,  
  57.          Scalar::all(-1), Scalar::all(-1),vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );     
  58.      imshow("draw",img_matches);  
  59.      waitKey(0);  
  60. }  

凌乱的Fast+Surf.descriptors+FlannBasedMatcher matcher;结果啊!


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值