Here is a snippet from descriptor_extractor_matcher.cpp sample available from OpenCV:
if( !isWarpPerspective && ransacReprojThreshold >= 0 ) { cout << "< Computing homography (RANSAC)..." << endl; vector<Point2f> points1; KeyPoint::convert(keypoints1, points1, queryIdxs); vector<Point2f> points2; KeyPoint::convert(keypoints2, points2, trainIdxs); H12 = findHomography( Mat(points1), Mat(points2), CV_RANSAC, ransacReprojThreshold ); cout << ">" << endl; } Mat drawImg; if( !H12.empty() )
Key lines for filtering are done here:
if( norm(points2[i1] - points1t.at<Point2f>((int)i1,0)) <= maxInlierDist )
Which measures the distance of the L2 norm between points (either 3 pixels, if nothing is specified, or a user-defined number of errors when reproducing pixels).
Hope this helps!
source share