in this answer I understand everything up to just before "// 5. Validate matches using RANSAC".
In my code, I use that code except for the part of ransacTest. I face the problem that I get too many "matches" that are wrong and/or sometimes the rectangle around the object my code finds is too distorted.
//Template image's corners
obj_corners[0] = cvPoint( 0, 0);
obj_corners[1] = cvPoint( best_img.cols, 0 );
obj_corners[2] = cvPoint( best_img.cols, best_img.rows );
obj_corners[3] = cvPoint( 0, best_img.rows );
obj.clear();
scene.clear();
for ( int i = 0; i < best_matches.size(); i++ )
{
//Get the keypoints from the good matches
obj.push_back( best_img_keypoints[ best_matches[i].queryIdx ].pt ); // Template image
scene.push_back( frame_keypoints[ best_matches[i].trainIdx ].pt ); // Frame
}
// -----Find homography----- //
std::vector<uchar> outlier_mask; //I don't use this line
cv::Mat H = findHomography( obj, scene, CV_RANSAC, reprojThres, outlier_mask);
cv::perspectiveTransform(obj_corners, scene_corners, H);
a) If I use fundamental matrix will I be able to use findHomography and perspectiveTransform?
b) Is there anything wrong in the above lines?