c++ - Improve matching of feature points with OpenCV -


i want match feature points in stereo images. i've found , extracted feature points different algorithms , need matching. in case i'm using fast algorithms detection , extraction , bruteforcematcher matching feature points.

the matching code:

vector< vector<dmatch> > matches; //using either flann or bruteforce ptr<descriptormatcher> matcher = descriptormatcher::create(algorithmname); matcher->knnmatch( descriptors_1, descriptors_2, matches, 1 );  //just temporarily code have right data structure vector< dmatch > good_matches2; good_matches2.reserve(matches.size());   (size_t = 0; < matches.size(); ++i) {      good_matches2.push_back(matches[i][0]);      } 

because there lot of false matches caluclated min , max distance , remove matches bad:

//calculation of max , min distances between keypoints double max_dist = 0; double min_dist = 100; for( int = 0; < descriptors_1.rows; i++ ) {     double dist = good_matches2[i].distance;     if( dist < min_dist ) min_dist = dist;     if( dist > max_dist ) max_dist = dist; }  //find "good" matches vector< dmatch > good_matches; for( int = 0; < descriptors_1.rows; i++ ) {     if( good_matches2[i].distance <= 5*min_dist )     {         good_matches.push_back( good_matches2[i]);      } } 

the problem is, either lot of false matches or few right ones (see images below).

many matches bad results http://codemax.de/upl/badmatchesfast.png only few matches http://codemax.de/upl/goodmatchesfast.png

i think it's not problem of programming more matching thing. far understood bruteforcematcher regards visual distance of feature points (which stored in featureextractor), not local distance (x&y position), in case important, too. has experiences problem or idea improve matching results?

edit

i changed code, gives me 50 best matches. after go through first match check, whether it's in specified area. if it's not, take next match until have found match inside given area.

vector< vector<dmatch> > matches; ptr<descriptormatcher> matcher = descriptormatcher::create(algorithmname); matcher->knnmatch( descriptors_1, descriptors_2, matches, 50 );  //look if match inside defined area of image double tresholddist = 0.25 * sqrt(double(leftimagegrey.size().height*leftimagegrey.size().height + leftimagegrey.size().width*leftimagegrey.size().width));  vector< dmatch > good_matches2; good_matches2.reserve(matches.size());   (size_t = 0; < matches.size(); ++i) {      (int j = 0; j < matches[i].size(); j++)     {     //calculate local distance each possible match     point2f = keypoints_1[matches[i][j].queryidx].pt;     point2f = keypoints_2[matches[i][j].trainidx].pt;             double dist = sqrt((from.x - to.x) * (from.x - to.x) + (from.y - to.y) * (from.y - to.y));     //save best match if local distance in specified area     if (dist < tresholddist)     {         good_matches2.push_back(matches[i][j]);         j = matches[i].size();     } } 

i think don't more matches, i'm able remove more false matches:

less better features http://codemax.de/upl/img001.png

an alternate method of determining high-quality feature matches ratio test proposed david lowe in paper on sift (page 20 explanation). test rejects poor matches computing ratio between best , second-best match. if ratio below threshold, match discarded being low-quality.

std::vector<std::vector<cv::dmatch>> matches; cv::bfmatcher matcher; matcher.knnmatch(descriptors_1, descriptors_2, matches, 2);  // find 2 nearest matches vector<cv::dmatch> good_matches; (int = 0; < matches.size(); ++i) {     const float ratio = 0.8; // in lowe's paper; can tuned     if (matches[i][0].distance < ratio * matches[i][1].distance)     {         good_matches.push_back(matches[i][0]);     } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -