cv::findHomography does not work [closed]

asked 2014-11-11 09:24:21 -0600

JohnyK. gravatar image

Hi,

I use the following code:

    //Points
    std::vector<cv::Point2f> detectedPoints;
    std::vector<cv::Point2f> localPoints;

    for (std::vector< cv::DMatch >::iterator i = matches.begin(); i != matches.end(); ++i)
    {
        detectedPoints.push_back(detectedKeyPoints.at(i->queryIdx).pt);
        localPoints.push_back(localKeyPoints.at(i->trainIdx).pt);
        std::cout << "Detected: " << detectedKeyPoints.at(i->queryIdx).pt << " Local: " << localKeyPoints.at(i->trainIdx).pt << std::endl;
    }

    cv::Mat H12;
    cv::Mat mask;

    H12 = cv::findHomography(detectedPoints, localPoints, mask, CV_RANSAC, 3);

    std::cout << mask << std::endl;

That is resulting in the following output:

Detected: [139.324, 160.001] Local: [139.323, 160]
Detected: [256.327, 212.994] Local: [256.323, 213]
Detected: [141.323, 140] Local: [141.323, 140]
Detected: [139.323, 141.001] Local: [187.323, 159]
Detected: [176.318, 61.9985] Local: [176.323, 62]
Detected: [255.328, 239.994] Local: [86.323, 218]
Detected: [133.318, 62.0009] Local: [126.323, 216]
[1; 1; 0; 0; 0; 1; 1]

Point 1 seems to be a good match so is point 2. But why is point 3 marked as outlier whereas points 6 and 7 are marked as inliers but they are definitely not.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-06 07:38:01.551108

Comments

This is a good question indeed... I wonder, do you show the results of the homography? I mean, I use a very similar code from a tutorial (http://docs.opencv.org/trunk/doc/tutorials/features2d/feature_homography/feature_homography.html?highlight=findhomography) and it allows me to visualize whether the results are good or not. I mean, with my understanding, the mask should show only inliers and it seems that it is not the case, but if you are able to get visually the correct outlines... It will show we don't understand how it works instead that maybe the parameters that you use are not relevant for your application. Have you changed the threshold? Or maybe used another function than RANSAC?

Doombot gravatar imageDoombot ( 2014-11-12 07:22:07 -0600 )edit