Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Understanding findHomography Mask

I apologize in advance if this is dumb but I am new to findHomography and trying to understand how to do object detection using it.

As I understand it, after using a keypoint detector, and a descriptor extractor, and filtering for points that are within some distance (e.g., 2-3 * the minimum distance), we only have a list of interesting points that are probably good individually but that may or may not match in pattern. That is where findHomography comes in. FindHomogrpahy is supposed to output a mask of both inliers (good points for a pattern) and outliers (bad points).

However, I never see anything saying how to interpret the output Mat from findHomography. It appears to be two dimensional but I do not know which column is the inliers and which the outliers. Also, I do not see anything which indicates how to conclude whether there was a match o not (i.e., is an absolute number of inliers determined to be a match or is it some measure of the inliers to outliers, etc.).

I have put some of my code below to give a sense of where I am.

Thanks for any help.

FlannBasedMatcher matcher;
std::vector< DMatch > matches, good_matches;
double max_dist;
double min_dist;
double dist;
Mat H;
std::vector<Point2f> obj;
std::vector<Point2f> scene;
Mat mask;

min_dist = 100;
max_dist = 0;

matcher.match(ObjectSurfDescriptors, SceneSurfDescriptors, matches);

for( int i = 0; i < ObjectSurfDescriptors.rows; i++ )
    dist = matches[i].distance;

    if( dist < min_dist ) 
        min_dist = dist;
    if( dist > max_dist ) 
        max_dist = dist;

for( int i = 0; i < ObjectSurfDescriptors.rows; i++ )
    if( matches[i].distance <= max(3*min_dist, 0.02) )
        good_matches.push_back( matches[i]); 

if(good_matches.size() >= MIN_GOOD_MATCHES)
    for( int i = 0; i < good_matches.size(); i++ )
        //-- Get the keypoints from the good matches
        obj.push_back( ObjectSurfKeypoints[ good_matches[i].queryIdx ].pt );
        scene.push_back( SceneSurfKeypoints[ good_matches[i].trainIdx ].pt );

    H = findHomography( obj, scene, CV_RANSAC, 3.0, mask );