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 );
}
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.
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?