I have a calibrated (virtual) camera in Blender that views a roughly planar object. I make an image from a first camera pose P0 and move the camera to a new pose P1. So I have the 4x4 camera matrix for both views from which I can calculate the transformation between the cameras as given below. I also know the intrinsics matrix K. Using those, I want to map the points from the image for P0 to a new image seen from P1 (of course, I have the ground truth to compare because I can render in Blender after the camera has moved to P1). If I only rotate the camera between P0 and P1, I can calculate the homography perfectly. But if there is translation, the calculated homography matrix does not take that into account. The theory says, after calculating M10, the last row and column should be dropped for a planar scene. However, when I check M10, I see that the translation values are in the rightmost column, which I drop to get the 3x3 homography matrix H10. Then, if there is no rotation, H10 is equal to the identity matrix. What is going wrong here?
Edit: I know that the images are related by a homography because given the two images from P0 and P1, I can find a homography (by feature matching) that perfectly maps the image from P0 to the image from P1, even in presence of a translational camera movement.
The theory became more clear to me after reading from two other books: "Multiple View Geometry" from Hartley and Zissermann (Example 13.2) and particularly "An Invitation to 3-D Vision: From Images to Geometric Models" (Section 5.3.1, Planar homography). Below is an outline, please check the above-mentioned sources for a thorough explanation.
Consider two images of points p
on a 2D plane P
in 3D space, the transformation between the two camera frames can be written as: X2 = R*X1 + T
(1) where X1
and X2
are the coordinates of the world point p
in camera frames 1 and 2, respectively, R
the rotation and T
the translation between the two camera frames. Denoting the unit normal vector of the plane P
to the first camera frame as N
and the distance from the plane P
to the first camera as d
, we can use the plane equation to write N.T*X1=d
(.T
means transpose), or equivalently (1/d)*N.T*X1=1
(2) for all X1
on the plane P
. Substituting (2) into (1) gives X2 = R*X1+T*(1/d)*N.T*X1 = (R+(1/d)*T*N.T)*X1
. Therefore, the planar homography matrix (3x3) can be extracted as H=R+(1/d)*T*N.T
, that is X2 = H*X1
. This is a linear transformation from X1
to X2
.
The distance d
can be computed as the dot product between the plane normal and a point on the plane. Then, the camera intrinsics matrix K
should be used to calculate the projective homography G = K * R+(1/d)*T*N.T * inv(K)
. If you are using a software like Blender or Unity, you can set the camera intrinsics yourself and thus obtain K
. For Blender, there a nice code snippet is given in this excellent answer.
OpenCV has some nice code example in this tutorial; see "Demo 3: Homography from the camera displacement".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With