Ask Your Question
1

Understanding findHomography Mask

asked 2014-07-26 18:22:44 -0600

pistorinoj gravatar image

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 );
}
edit retag flag offensive close merge delete

Comments

Homography matrix is a perspective transformation matrix containing coefficients thereof. Its parameters do not indicate inliers, outliers etc. http://en.wikipedia.org/wiki/Homography_%28computer_vision%29

It is the result of finding corresponding pairs, matching them, and finding such a matrix that would transform coordinates of points from one image to the other image.

Witek gravatar imageWitek ( 2014-07-27 06:03:01 -0600 )edit

Thanks. I am using this as a guide http://docs.opencv.org/trunk/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.html I also see references to stuff like this. http://answers.opencv.org/question/12295/compute-inliers-for-a-homography/ Maybe it would be easier if I just ask, having extracted the good_matches, what criteria do you use/how do you decide if you have a match?

pistorinoj gravatar imagepistorinoj ( 2014-07-27 17:10:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-10-31 15:26:46 -0600

Doombot gravatar image

You ask about the mask output of "findHomography". Here is what I can tell you about.

Actually, even if it is 2-dimensional, there is "n" rows and 1 column. "n" is exactly the number of matches that is present in the "scene" variable of your code. In my case, "scene" is of size = 55, so there are 55 rows in the mask. Some of the bits are at 0 and some are at 1.

You could then "compare" (logical AND) good_matches[i] && mask[i] and you would get which of the good_matches fit (are inliers, 1) in the homography and by extension which ones are the outliers ( 0 ).

If you need more info feel free to ask!

edit flag offensive delete link more

Comments

Thanks. This sounds right so let me play around with it.

pistorinoj gravatar imagepistorinoj ( 2014-11-13 13:50:41 -0600 )edit

Does 'H' matrix contains the average translation and rotation between two frames???

Safeer_Aabbasi gravatar imageSafeer_Aabbasi ( 2017-01-29 11:44:33 -0600 )edit

@Doombot, does the position of the first row in the mask correlate to the first good_match and the first row in both keypoints? If not, how can I refine my keypoints list so that I only keep the inliers?

hayley gravatar imagehayley ( 2018-09-14 04:03:58 -0600 )edit

how can i get the exact location for every inlier point for example i need to know x and y location for all inliers points or all matched points

fo2sh44 gravatar imagefo2sh44 ( 2018-10-15 12:53:32 -0600 )edit

Question Tools

Stats

Asked: 2014-07-26 18:22:44 -0600

Seen: 10,308 times

Last updated: Oct 31 '14