Reputation: 61
I got confused with the outputs of opencv decomposeProjectionMatrix function.
I have the projection matrix and the camera matrix "K" and I want to get the translation vector "t"and the Rotation matrix "R" from the projection matrix
As I know the projection matrix of dimension 3*4 = K[R|t] in which "t" is a 3*1 vector
cv2.decomposeProjectionMatrix returns R with dimension 3*3 which is correct but the transVect returned is of dimension 4*1 not 3*1
My question is how to get back the projection matrix from the function outputs?
documentation: https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html
Upvotes: 4
Views: 8302
Reputation: 86
You have to normalise it by the last number: t = t[:3] / t[3]
But for some reason, you need to multiply it by -1. Here is my example:
k = np.array([[631, 0, 384],
[ 0, 631, 288],
[ 0, 0, 1]])
r = np.array([[-0.30164902, 0.68282439, -0.66540117],
[-0.63417301, 0.37743435, 0.67480953],
[ 0.71192167, 0.6255351 , 0.3191761 ]])
t = np.array([ 3.75082481, -1.18089565, 1.06138781])
C = np.eye(4)
C[:3, :3] = k @ r
C[:3, 3] = k @ r @ t
out = cv2.decomposeProjectionMatrix(C[:3, :])
and out
gives the following:
out[0]:
array([[631., -0., 384.],
[ 0., 631., 288.],
[ 0., 0., 1.]])
out[1]:
array([[-0.30164902, 0.68282439, -0.66540117],
[-0.63417301, 0.37743435, 0.67480953],
[ 0.71192167, 0.6255351 , 0.3191761 ]])
out[2]:
array([[-0.89432836],
[ 0.28156699],
[-0.25307213],
[ 0.23843512]])
If you apply the normalisation, you get:
array([[-3.75082481],
[ 1.18089565],
[-1.06138781]])
what is actually a -t
.
However np.linalg.inv(C[:3, :3]) @ C[:3, 3]
gives the correct result
array([ 3.75082481, -1.18089565, 1.06138781])
Upvotes: 2
Reputation: 1
C = K[R|t] = K(R|Rt) = (KR|KRt) = (M | Mt)
The fourth column of C is c4.
Mt = c4.
t = M^(-1)c4
ref https://www.ics.uci.edu/~majumder/vispercep/cameracalib.pdf
Upvotes: 0