[Math] How to find camera position and rotation from a 4×4 matrix

computer visionmatrices

To find the intrinsic and extrinsic parameters I calibrated it and the software gave me the extrinsic parameters as a 4 x 4 matrix.
This seems to be a 4×4 homogeneous transformation matrix.

The values are as follows

$$ \left(
\begin{array}
0.211 & -.306 & -.928 & .789 \\
.662 & .742 & -.0947 & .147 \\
.718 & -.595 & .360 & 3.26 \\
0 & 0 &0 & 1 \\
\end{array}
\right)
$$
I also have the intrinsic parameters of the camera like focal length, principal point, skew, distortion co-efficients etc.

How do I extract the camera position and rotation in world co-ordinates using this matrix?

EDIT:

cam image

On the left I have shown a cam and its viewing a 3d object, and I take a photo of this 3D object from the cam.
THe right is what I want. I want to get the world postion/rotation of the cam and the world positon/rotation and actual size of the image in 3d space.

Best Answer

Assuming your matrix is an extrinsic parameter matrix of the kind described in the Wikipedia article, it is a mapping from world coordinates to camera coordinates. So, to find the position $C$ of the camera, we solve

$$\begin{align*}0 &= RC + T\\ C &= -R^T T \approx (-2.604, 2.072, -0.427).\end{align*}$$

The orientation of the camera is given simply by $R^T.$ So if the "in" axis is the z-axis, for instance, then the vector pointing in the direction the camera is pointing is

$$R^T \left[\begin{array}{c}0\\0\\1\end{array}\right] = (0.718, -0.595, 0.36).$$

Related Question