Created
March 7, 2013 17:55
-
-
Save berak/5110164 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2/highgui/highgui.hpp" | |
#include "opencv2/calib3d/calib3d.hpp" | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include "opencv2/features2d/features2d.hpp" | |
#include "opencv2/nonfree/nonfree.hpp" | |
#include <iostream> | |
#include <fstream> | |
using namespace cv; | |
using namespace std; | |
/*** | |
program detector extracto matcher | |
DETECTORS | |
• "FAST" – FastFeatureDetector | |
• "STAR" – StarFeatureDetector | |
• "SIFT" – SIFT (nonfree module) | |
• "SURF" – SURF (nonfree module) | |
• "ORB" – ORB | |
• "BRISK" – BRISK | |
• "MSER" – MSER | |
• "GFTT" – GoodFeaturesToTrackDetector | |
• "HARRIS" – GoodFeaturesToTrackDetector with Harris detector enabled | |
• "Dense" – DenseFeatureDetector | |
• "SimpleBlob" – SimpleBlobDetector | |
Also a combined format is supported: feature detector adapter name ( "Grid" – GridAdaptedFeatureDetector, | |
"Pyramid" – PyramidAdaptedFeatureDetector ) + feature detector name (see above), for example: "GridFAST", | |
"PyramidSTAR" . | |
EXTRACTORS | |
• "SIFT" – SIFT | |
• "SURF" – SURF | |
• "ORB" – ORB | |
• "BRISK" – BRISK | |
• "BRIEF" – BriefDescriptorExtractor | |
A combined format is also supported: descriptor extractor adapter name ( "Opponent" – | |
OpponentColorDescriptorExtractor ) + descriptor extractor name (see above), for example: "OpponentSIFT" . | |
MATCHERS | |
– BruteForce (it uses L2 ) | |
– BruteForce-L1 | |
– BruteForce-Hamming | |
– BruteForce-Hamming(2) | |
– FlannBased | |
***/ | |
struct PointMatcher | |
{ | |
Ptr<FeatureDetector> detector; | |
Ptr<DescriptorExtractor> extractor; | |
Ptr<DescriptorMatcher> matcher; | |
PointMatcher(string detect, string extract, string match) | |
{ | |
detector = FeatureDetector::create( detect ); | |
extractor = DescriptorExtractor::create( extract ); | |
matcher = DescriptorMatcher::create( match ); | |
} | |
void match( const Mat& img1, const Mat& img2, vector<DMatch>& matches12, vector<KeyPoint> &keys1, vector<KeyPoint> &keys2 ) | |
{ | |
Mat desc1, desc2; | |
detector->detect( img1, keys1 ); | |
cerr << "."; | |
detector->detect( img2, keys2 ); | |
cerr << "."; | |
extractor->compute( img1, keys1, desc1 ); | |
cerr << ":"; | |
extractor->compute( img2, keys2, desc2 ); | |
cerr << ":"; | |
//matcher->knnMatch( desc1, desc2, matches12, 5 ); | |
matcher->match( desc1, desc2, matches12 ); | |
cerr << "!" << endl; | |
} | |
}; | |
int main(int argc, char** argv) | |
{ | |
cv::initModule_nonfree(); | |
string detect="ORB"; | |
if ( argc > 1 ) detect = argv[1]; | |
string extract="ORB"; | |
if ( argc > 2 ) extract = argv[2]; | |
string match="BruteForce"; | |
if ( argc > 3 ) match = argv[3]; | |
PointMatcher points(detect,extract,match); | |
//PointMatcher points("GFTT","ORB","BruteForce-Hamming"); | |
vector<KeyPoint> keys1, good1; | |
vector<KeyPoint> keys2, good2; | |
vector<DMatch> matches; | |
namedWindow("m1",0); | |
namedWindow("m2",0); | |
{ | |
Mat m1 = imread( "E:/code/opencv242/p/stereo24/l/0246.pgm"); | |
Mat m2 = imread( "E:/code/opencv242/p/stereo24/r/0246.pgm"); | |
if ( (!m1.empty()) && (!m2.empty()) ) | |
{ | |
points.match( m1,m2,matches,keys1,keys2 ); | |
cerr << detect << "." << extract << "." << match << " : " << matches.size() << " " << keys1.size() << " " << keys2.size() << endl; | |
if ( (!keys1.empty()) && (!keys2.empty()) ) | |
{ | |
drawKeypoints(m1,keys1,m1,Scalar(200,0,0)); | |
drawKeypoints(m2,keys2,m2,Scalar(0,0,200)); | |
for ( size_t i=0; i<matches.size(); i++ ) | |
{ | |
DMatch & dm = matches[i]; | |
Point p1(keys1[dm.queryIdx].pt); | |
Point p2(keys2[dm.trainIdx].pt); | |
circle(m1,p2,3,Scalar(0,0,200)); | |
circle(m2,p2,3,Scalar(0,200,200)); | |
} | |
//drawMatches( m1, keys1, m2, keys2, matches, m1 ); | |
} | |
imshow("m1",m1); | |
imshow("m2",m2); | |
waitKey(0); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment