Question

I'm currently finishing my evaluation-tool for interest point detectors. In the last steps I found a confusing error.

Mat findHomography(InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray() )

The srcPoints and dstPoints are vector<Points2f> which stores the corresponding points of the matched keypoints. So far nothing special - It's like in the tutorials.

But when I use RANSAC and have a vector<Points2f> in range [0, ... , 4], I get an assertion error than the counter should be greater or equals four.

Question 1: Does the algorithm needs at least four points to describe what belongs to the current model or not and to create the consensus?

Question 2: Is there any documentation about this? (I took a look at the doc and the tutorials.)

Please note that I already have seen this question. But there is no satisfying answer for the behaviour of RANSAC. Or should I accept that this methods needs at least four points to find the homography?

Thanks for your help.

Was it helpful?

Solution

A homography cannot be computed with less than 4 pairs of points. That is because with only 3 points there is a perspective ambiguity. Picture a triangle

a


b        c

in image 1. In image 2 the points have been transformed to look like this

a


b    c

The distance between b and c has been cut in half. Unfortunately you don't know if that is because point c got closer to your or farther from you. With a 4th point the difference becomes clear.

a        d


b        c

Here is a square in image 1

     d


a        


b    c    

here d and c rotated towards you

a     

     d
b    c   

and here they rotated away from you.

I don't see this requirement in the openCV documentation but if you find any resources on homography calculation you won't have to read very far before you find this requirement and a more rigorous proof of 4 points being sufficient.

OTHER TIPS

RANSAC is used to select 4 pairs of matching points in a greater set or correspondences (i.e. when srcPoints.size() >= 4). That's why you get an error if srcPoints.size() <=4.

You need at least 4 correspondences simply because a Homography matrix H has 8 degrees of freedom, hence 8 linear equations are required to find a solution. Since each pairs of points generates two linear equations (using x and y coordinates) you'll need a total of at least 4 correspondences.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top