why do BestOf2NearestMatcher change keypoints position

asked 2014-08-12 13:40:33 -0600

s093294 gravatar image

updated 2014-08-12 14:35:55 -0600

What is the point of

    Point2f p = features1.keypoints[m.queryIdx].pt;
    p.x -= features1.img_size.width * 0.5f;
    p.y -= features1.img_size.height * 0.5f;
    src_points.at<Point2f>(0, static_cast<int>(i)) = p;

    p = features2.keypoints[m.trainIdx].pt;
    p.x -= features2.img_size.width * 0.5f;
    p.y -= features2.img_size.height * 0.5f;
    dst_points.at<Point2f>(0, static_cast<int>(i)) = p;

in BestOf2NearestMatcher ?

the surf homography example dont seem to do this, but simply uses the points as is.

The reason why i ask is that I see a small ofset (permanent) in warped images if I use the BestOf2NearestMatcher to estimate H, but not if just using the translated points.

I made the following test and was able to verify that the point translations are causing my issues.

    for (size_t i = 0; i < good_matches.size(); i++)
    {
        //-- Get the keypoints from the good matches
        obj.push_back(features1.keypoints[good_matches[i].queryIdx].pt);
        scene.push_back(features2.keypoints[good_matches[i].trainIdx].pt);
        const cv::DMatch& m = good_matches[i];

        cv::Point2f p = features1.keypoints[m.queryIdx].pt;
        p.x -= features1.img_size.width * 0.5f;
        p.y -= features1.img_size.height * 0.5f;
        src_points.at<cv::Point2f>(0, static_cast<int>(i)) = p;

        p = features2.keypoints[m.trainIdx].pt;
        p.x -= features2.img_size.width * 0.5f;
        p.y -= features2.img_size.height * 0.5f;
        dst_points.at<cv::Point2f>(0, static_cast<int>(i)) = p;
    }


    info.H = findHomography(src_points, dst_points, cv::RANSAC); //this is wronge
    info.H = findHomography(obj, scene, cv::RANSAC); //this is correct

I would like to take benefit of the BestOf2NearestMatcher instead of manually finding best matches.

edit retag flag offensive close merge delete