I am calculating an homography between two images img1
and img2
(the images contain mostly one planar object, so the homography works well between them) using standard methods in OpenCV in python. Namely, I compute point matches between the images using sift and then call cv2.findHomography
.
To make the computation faster I scale down the two images into small1
and small2
and perform the calculations on these smaller copies, so I calculate the homography matrix H
, which maps small1
into small2
.
However, at the end, I would like to use calculate the homography matrix to project one full-size image img1
onto the other the full-size image img2
.
I thought I could simply transform the homography matrix H
in the following way H_full_size = A * H * A_inverse
where A
is the matrix representing the scaling from img1
to small1
and A_inverse
is its inverse.
However, that does not work. If I apply cv2.warpPerspective
to the scaled down image small1
with H
, everything goes as expected and the result (largely) overlaps with small2
. If I apply cv2.warpPerspective
to the full size image img1
with H_full_size
the result does not map to img2
.
However, if I project the point matches (detected on the scaled down images) using A
(using something like projected_pts = cv2.perspectiveTransform(pts, A)
) and then I calculate H_full_size
from these, everything works fine.
Any idea what I could be doing wrong here?