Repository navigation
Fix the bug in case determinant of rotation matrix is -1 - #13601
Conversation
|
I will rebase this patch. |
|
Done (updated branch in your GitHub fork). Please update your local git repository (on your machine). Could you capture problem inputs and create simple test for this case (to avoid future regressions)? Update: Inputs are available in original issue. |
|
Added test |
|
@alalek Thank you for your kind help. I recognize that it depends on whether and how we check the result furtherly. As we know, homography can be induced by pure rotation or planar scenes. And in your test, you set translation as vector 0. It seems that you cionsider pure rotation. I have a doubt whether these two kinds of homographies are consistent. Since in the case of planar scene, homography strongly relies on the plane in real world. But in image mosaicing (pure rotation), the homography is (theoretically) unique for two images. Since we are discussing camera calibration and 3D reconstruction, it seems strange that the camera center never moves. (I'm not saying your test is wrong. It's just an example to check the result. I am consulting the differences between these two homographies.) Since your test doesn't consider translation, here I give an example. I'm so sorry I didn't know the format of test and how to write code like that, so I didn't create the test. But we can discuss here with more freedom. By the way, if the homography considers pure rotation, the estimated normal of the plane makes no sense. If the homography considers planar scene, the input of function findHomography should be coplanar points, right? As I said at the beginning, we need to check the result, so the code before is not wrong. You just implement the algorithms of HomographyDecompInria and HomographyDecompZhang according to related references. The results of these methods should be checked by us manually. The reason why I say this is that I realize the simple check of det(R) > 0 (as I pulled request) is far from enough. Suppose Using Zhang's method (you use Inria's as default) implemented in opencv (considering there may be difference between two intrinsic matrixes. But in this case, I set them the same), I get the following results: Total number of solutions: 8 R = R = R = R = R = R = R = R = As you can see, det(R) may even be 0.00537154, which is larger than 0, too. Maybe it's because the homofgraphy itself is wrong, but as an example, it can reflect some facts of the code. So for more accurate results, we should write the code like this: Actually, if we estimate homography from features (such as points and lines), the estimated rotation R and translation t should meet that (theoretically) all features are in front of both cameras. So we can check further. But simply choosing the pose with most features in the front is thoughtless. just for (R, t) and (R, -t), we may do it like this. In my test, there are still two sulutions to be checked after the steps above. Maybe we can check through the normal. Since the feature points are from the same plane, a line segment formed by any two of these points (theoretically) ought to be perpendicular to the normal. Then we may get the final one. I just analyze like this, but still don't have a try. Of course, the funtion decomposeHomographyMat itself doesn't need to check by features. The above paragraph is just to discuss. Last but not least, when I use 4 points to calculate homography and decompose it, the result (R and t) changes a lot even with one small pixel change of a point. So you provide robust methods such as RANSAC. I'm not so good at reading code. Could you tell me how you estimate homography robustly, randomly select 4 points every time and choose the best one, or estimate it based on so many points? I'd like to have a try in the former way, but don't know how to choose the best one (in detail). Oh, could you tell me the right steps to pull request in detail (code) if I want to change it like what I said above? Thank you so much. |
* Fix the bug in case determinant of rotation matrix is -1 * calib3d(test): check det(R) == 1
resolves #4978
Fix the bug in case determinant of rotation matrix is -1