Is the recoverPose() function in OpenCV is left-handed?
Asked Answered
M

3

7

I run simple test for OpenCV camera pose estimation. Having a photo and the same photo scaled up (zoomed in) I use them to detect features, calculate essential matrix and recover camera poses.

Mat inliers;
Mat E = findEssentialMat(queryPoints, trainPoints, cameraMatrix1, cameraMatrix2,
                         FM_RANSAC, 0.9, MAX_PIXEL_OFFSET, inliers);

size_t inliersCount =
    recoverPose(E, queryGoodPoints, trainGoodPoints, cameraMatrix1, cameraMatrix2, R, T, inliers);

So when I specify the original image as the first one, and the zoomed image as the second one, I get translation T close to [0; 0; -1]. However the second camera (zoomed) is virtually closer to the object than the first one. So if Z-axis goes from image plane into the scene, the second camera should have positive offset along Z-axis. For the result I get, Z-axis goes from the image plane towards camera, which among with other axes (X goes right, Y goes down) forms left-handed coordinate system. Is that true? Why this result differs from the coordinate system illustrated here?

Meliorate answered 14/6, 2016 at 11:4 Comment(0)
F
9

According to the OpenCV document, the algorithm in the function recoverPose is based on the paper "Nistér, D. An efficient solution to the five-point relative pose problem, CVPR 2003." From equations in Section 2 in this paper, we know it uses the basic triangle relationship (see figure here):

x2 = R*x1 + t

Therefore, translation t is the vector from cam2 to cam1 in cam2 frame. This explains why you get the answer t close to [0; 0; -1].

Flowerer answered 16/8, 2017 at 21:1 Comment(1)
So if I want get the "correct" t and R, I should: 1) invert the homogenousE, then 2) recoverPose() ?Heathenish
M
2

Seems the recoverPose() function returns the first camera transform relatively to the second one (which was not intuitive for me, and is not clearly stated in the documentation). With this assumption test works correctly.

Meliorate answered 14/6, 2016 at 13:52 Comment(0)
V
1

In this diagram

diagram

origin is located at top-right corner. Hence it satisfies right hand coordinate system. Positive Z-axis of image and camera coordinate systems are in SAME direction.

However, in openCV, image coordinate system is located at top-left corner. So, it satisfies left hand coordinate system. Positive Z-axis of image and camera coordinate systems are in OPPOSITE direction.

Vacuity answered 18/4, 2020 at 6:15 Comment(1)
So an extension of what you said is if I want to represent second camera marked with [I, J, K] in [X, Y, Z] coordinate system, I should actually use R' = tranpose(R) and t' = -transpose(R) dot tPhotofluorography

© 2022 - 2024 — McMap. All rights reserved.