# Too many outliers in findHomography

Hello everyone. I come here because I have some troubles using findHomography. I have to datasets of (x, y) points, one reference and one current. Here the example given by:

std::cout << ReferenceImage_pts << std::endl << ImageToRegister_pts << std::endl;

[1221.7125, 918.77368;
734.95111, 287.90887;
1274.4686, 824.61401;
137.96986, 264.46851;
44.125511, 793.7464;
16.055382, 400.53168;
85.167656, 449.41504;
664.56403, 267.73035;
1135.332, 206.07474;
240.12773, 758.36615]

[1220.592, 917.02393;
733.86157, 286.13693;
1273.3839, 822.82416;
137.79268, 261.71985;
43.028145, 792.05322;
664.46063, 265.02847;
14.848706, 398.8092;
1134.2389, 204.29382;
84.96907, 446.72897;
239.95021, 755.71704]


As you can see, it's very easy to visually match correspondant points. But, when I use findHomography, it only find 6 inliers ... Very far to have a good transformation matrix.

Here the code I use to find H and to change the perspective:

H = findHomography(ReferenceImage_pts, ImageToRegister_pts, CV_RANSAC, 3, outputMask);
warpPerspective(in, out, H.inv(), in.size());


Am I doing something wrong ? In this case I just use 10 points as you can see. However, in fact I have more than 200 points. But if I try to use all the points, it is worst. Only 2% of inliers.

EDIT : What I think: I should try to match points by putting outliers at the end of the set. But I thought findHomography was doing this. I don't understand and I don't know how I can do it.

I hope someone could help me. Cheers.

edit retag close merge delete

Could you explain/show how do you get your points (ReferenceImage_pts, ImageToRegister_pts) in the first place?

( 2015-05-21 13:02:49 -0500 )edit

For example, here is the tutorial suggested by OpenCV:http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography

( 2015-05-21 13:06:17 -0500 )edit

In fact I use an homemade algorithm so I don't use the features2d.

I work on astronomical images: these points are stars coordinates (x, y). This algorithm works and is very accurate. So I just want to use the data coming from the algorithm. I think I only need to match the two data sets before findHomography, but I'm not sure about it.

( 2015-05-21 15:57:13 -0500 )edit

Sort by » oldest newest most voted

findHomography's implementation in OpenCV comes with some assumptions behind. In the "standard" case of use, you detect keypoints (x,y coordinates) in two images. According to the comments, you get keypoints as coordinates of stars from another algorithm. Now, in the standard case, you compute a "descriptor" for each keypoint in both images. I don't want to delve too much in the details, but it is a way to almost "uniquely" distinguish a keypoint from another.

When you have computed all the descriptors, you use a matching algorithm to pair a keypoint from the first set of point to a keypoint from the second set. The matching algorithm often just compare all the descriptors and pair the most similar. A good proportion of actual outliers may be matched this way, but for the usual application it is okay. Then, you use findHomography as you did and usually, good results arise.

In OpenCV's implementation of findHomography, the assumption is that all the points in input set 1 are already paired with a plausible match in the input set 2. This is where I see a problem with your use of findHomography; I am not sure that you have some way to pair those plausible matches.

In the literature, algorithms exist to match two sets of (x,y) based on their coordinates. One of them is RANSAC, and it is used in findHomography, even if it is in a form not directly of use for you.

If you ever used Matlab, this library implements RANSAC and could be of use to you: https://github.com/RANSAC/RANSAC-Toolbox

more

Thanks for this good answer It's exactly what I was thinking. However I don't use matlab : only C and C++. I would like to find a in RANSAC implementation in C. It would be so nice and easier for me. But so far my searches failed.

Nevertheless, thank you very much.

EDIT : in fact, I think this is my missing part : http://www.wikiwand.com/en/Correspond...

( 2015-05-22 10:36:40 -0500 )edit

You could look at this: http://www.mrpt.org/tutorials/mrpt-ex... This was not applicable for me but MAYBE it could fit your needs

( 2015-05-22 14:31:00 -0500 )edit

Oh thanks, that's too nice. However, the link http://www.mrpt.org/tutorials/mrpt-ex... is dead :/

( 2015-05-23 04:16:10 -0500 )edit
1

I maybe found it at : https://github.com/jlblancoc/mrpt/blo... Thanks

( 2015-05-23 04:37:46 -0500 )edit

That's it!

( 2015-05-25 13:26:57 -0500 )edit

Official site

GitHub

Wiki

Documentation