Ask Your Question
0

Stereo matching problem

asked 2013-11-06 11:34:09 -0600

w.wang8389 gravatar image

updated 2013-11-06 11:34:54 -0600

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 ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-11-07 02:07:43 -0600

JohannesZ gravatar image

Concerning the matching strategy, search for the terms "nearest neighbor distance ratio" and "cross matching". Also, you can test your point-correspondences against a model such as a homography or the fundamental matrix.

By the way, the fundamental matrix is a very important criterion for your stereo-matching application! :-)

Also the openCV-book from Laganiere is a good start...

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-11-06 11:34:09 -0600

Seen: 941 times

Last updated: Nov 07 '13