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特征点带入计算。这也就是一种无心的玩闹,看看了了)
- #include <opencv2/core/core.hpp>
- #include <opencv2/features2d/features2d.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <vector>
- #include <iostream>
- using namespace cv;
- using namespace std;
- char img_filename1[]="D:/src.jpg";
- char img_filename2[]="D:/Demo.jpg";
- void main()
- {
- Mat src1,src2;
- src1 = imread(img_filename1,1);
- src2 = imread(img_filename2,1);
- // vector of keyPoints
- vector<KeyPoint> keys1;
- vector<KeyPoint> keys2;
- // construction of the fast feature detector object
- FastFeatureDetector fast1(40); // 检测的阈值为40
- FastFeatureDetector fast2(40);
- // feature point detection
- fast1.detect(src1,keys1);
- double t;
- t=getTickCount();
- fast2.detect(src2,keys2);
- t=getTickCount()-t;
- t=t*1000/getTickFrequency();
- cout<<"KeyPoint Size:"<<keys2.size()<<endl;
- cout<<"extract time:"<<t<<"ms"<<endl;
- drawKeypoints(src1, keys1, src1, Scalar::all(-1), DrawMatchesFlags::DRAW_OVER_OUTIMG);
- drawKeypoints(src2, keys2, src2, Scalar::all(-1), DrawMatchesFlags::DRAW_OVER_OUTIMG);
- imshow("FAST feature1", src1);
- imshow("FAST feature2", src2);
- cvWaitKey(0);
- t=getTickCount();
- SurfDescriptorExtractor Extractor;//Run:BruteForceMatcher< L2<float> > matcher
- //ORB Extractor;//Not Run;
- //BriefDescriptorExtractor Extractor;//RUN:BruteForceMatcher< Hamming > matcher
- Mat descriptors1, descriptors2;
- Extractor.compute(src1,keys1,descriptors1);
- Extractor.compute(src2,keys2,descriptors2);
- //BruteForceMatcher< Hamming > matcher;
- //BruteForceMatcher< L2<float> > matcher;
- FlannBasedMatcher matcher;
- vector< DMatch > matches;
- matcher.match( descriptors1, descriptors2, matches );
- t=getTickCount()-t;
- t=t*1000/getTickFrequency();
- cout<<"match time:"<<t<<"ms"<<endl;
- Mat img_matches;
- drawMatches( src1, keys1, src2, keys2, matches, img_matches,
- Scalar::all(-1), Scalar::all(-1),vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
- imshow("draw",img_matches);
- waitKey(0);
- }
凌乱的Fast+Surf.descriptors+FlannBasedMatcher matcher;结果啊!