I've tried SIFT, SURF, BRISK, but it seems none of them works fine on my images. Can anyone give me a hint on how to generate good matching result? Or can anyone try his/her code to see if good result is achievable?
Here is my code:
string pFile = "F:\\1.bmp";
Mat pMat1 = imread(pFile,CV_LOAD_IMAGE_GRAYSCALE);
pFile = "F:\\3.bmp";
Mat pMat2 = imread(pFile,CV_LOAD_IMAGE_GRAYSCALE);
// ************ SIFT ********************
//-- Step 1: Detect the keypoints using BRISK Detector
int iBestSiftFeatures = 50; // The number of best features to retain. The features are ranked by their scores (measured in SIFT algorithm as the local contrast)
int iLayersInEachOctave = 3; // The number of layers in each octave. 3 is the value used in D. Lowe paper. The number of octaves is computed automatically from the image resolution.
double dContrastThreshold = 0.06; //The contrast threshold used to filter out weak features in semi-uniform (low-contrast) regions. The larger the threshold, the less features are produced by the detector.
double dEdgeThreshold = 10; // The threshold used to filter out edge-like features. Note that the its meaning is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are filtered out (more features are retained).
double dSigma = 0.6; // The sigma of the Gaussian applied to the input image at the octave #0. If your image is captured with a weak camera with soft lenses, you might want to reduce the number.
SiftFeatureDetector SFdetector(iBestSiftFeatures, iLayersInEachOctave, dContrastThreshold, dEdgeThreshold, dSigma);
vector<KeyPoint> keypointsSiftA, keypointsSiftB;
Mat descriptorsSiftA, descriptorsSiftB;
SFdetector.detect(pMat1, keypointsSiftA);
SFdetector.detect(pMat2, keypointsSiftB);
//-- Step 2: Calculate descriptors (feature vectors)
SFdetector.compute(pMat1, keypointsSiftA, descriptorsSiftA);
SFdetector.compute(pMat2, keypointsSiftB, descriptorsSiftB);
//-- Step 3: Matching
BFMatcher Siftmatcher(NORM_L2);
//FlannBasedMatcher Bmatcher(new flann::LshIndexParams(200,10,5));
vector< DMatch > Siftmatches;
Siftmatcher.match( descriptorsSiftA, descriptorsSiftB, Siftmatches );
//-- Step 4: Draw match
Mat all_matches;
drawMatches( pMat1, keypointsSiftA, pMat2, keypointsSiftB,
Siftmatches, all_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
imshow( "SIFT All Matches", all_matches );
waitKey(0);
return 0;
// ************ SIFT ********************
// ************ BRISK ********************
//-- Step 1: Detect the keypoints using BRISK Detector
int Threshl = 180;
int Octaves = 4; //(pyramid layer) from which the keypoint has been extracted
float PatternScales = 1.0f;
BRISK BRISKD(Threshl,Octaves,PatternScales);//initialize algoritm
BRISKD.create("Feature2D.BRISK");
vector<KeyPoint> keypointsA, keypointsB;
Mat descriptorsA, descriptorsB;
BRISKD.detect(pMat1, keypointsA);
BRISKD.detect(pMat2, keypointsB);
//-- Step 2: Calculate descriptors (feature vectors)
BRISKD.compute(pMat1, keypointsA,descriptorsA);
BRISKD.compute(pMat2, keypointsB,descriptorsB);
//-- Step 3: Matching
//BFMatcher Bmatcher(NORM_HAMMING);
FlannBasedMatcher Bmatcher(new flann::LshIndexParams(200,10,5));
vector< DMatch > Bmatches;
Bmatcher.match( descriptorsA, descriptorsB, Bmatches );
//-- Step 4: Draw match
Mat all_Siftmatches;
drawMatches( pMat1, keypointsA, pMat2, keypointsB,
Bmatches, all_Siftmatches, Scalar::all(-1), Scalar::all(-1),
vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
imshow( "BRISK All Matches", all_matches );
waitKey(0);
return 0;
// ************ BRISK ********************
// ************ SURF ********************
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 8400;
SurfFeatureDetector detector( minHessian );
vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( pMat1, keypoints_1 );
detector.detect( pMat2, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute( pMat1, keypoints_1, descriptors_1 );
extractor.compute( pMat2, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors with a brute force matcher
BFMatcher matcher(NORM_L2);
vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
//-- Draw matches
Mat img_matches;
drawMatches( pMat1, keypoints_1, pMat2, keypoints_2, matches, img_matches );
//-- Show detected matches
imshow("Matches", img_matches );
waitKey(0);![image description](/upfiles/13837591637349685.bmp)
return 0;
// ************ SURF ********************
Thank you. Any suggestion and help is appreciated