laurentkneip / opengv

OpenGV is a collection of computer vision methods for solving geometric vision problems. It is hosted and maintained by the Mobile Perception Lab of ShanghaiTech.
Other
1.02k stars 353 forks source link

P3P algorithm fails with coplanar feature/bearing vectors #21

Open fred41 opened 8 years ago

fred41 commented 8 years ago

Hey,

first thanks for developing a new P3P solving algorithm and for this interesting library.

I am currently reading your paper: "A Novel Parametrization of the Perspective-Three-Point Problem for a Direct Computation of Absolute Camera Position and Orientation" While running the related code, i found a problem with a specific feature/bearing vector configuration.

Let me use the notation from the paper for problem description:

When all 3 feature vectors f are coplanar (all 3 camera points in a line at sensor plane), then t(z) will be orthogonal to f(3). This results in a f(3)z (in intermediate camera frame) of zero and the algorithm fails (since we will divide by zero later).

Are you aware of this problem? The current code seems not to be prepared to handle this case.

Cheers

laurentkneip commented 8 years ago

True. This is a trivial case though, as those three vectors being coplanar tells you immediately that the camera must lie in plane defined by the three points. Can you try to catch this case and make a pull request?

fred41 commented 8 years ago

Theta is 0 or Pi in this case. We just need to find alpha. So it should be doable (even for a non mathematician like me :). I will let you know if i have a working solution.

fred41 commented 8 years ago

Another common case that isn't handled: Plane f(1)|f(2), orthogonal to plane f(1)|f(3). f(3)y becomes zero (in intermediate camera frame), we divide by zero later, too.

EDIT: just added a refined check for 'divide by zero' cases. Handles all possible cases now.

madcowswe commented 7 years ago

Me and a colleague had some issues with the algorithm (we intend to use it with the camera operating in the plane of the points), and when we inspected the paper closer, we found the same 2 issues you did. We were about to go do something about it, when we found this PR. Thanks @fred41 for sharing your fix! And of course thanks to @laurentkneip for the original algorithm. This is why open source is great!

madcowswe commented 7 years ago

@fred41 @laurentkneip We found that the current proposed solutions cannot handle the case when all three feature vectors are mutually orthogonal, i.e. f1, f2 and f3 are all orthogonal to each other. Then no possible re-assigning between the labeling of the points and feature vectors will solve the fact that f3_y is zero. How can we solve this? Both phi1 and phi2 are zero. Is the correct approach to go back to Eq 7 in the paper and set the two top components to zero, and solve from there?