homography and image scaling in opencv
<p>I am calculating an homography between two images <code>img1</code> and <code>img2</code> (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 <code>cv2.findHomography</code>.</p>

<p>To make the computation faster I scale down the two images into <code>small1</code> and <code>small2</code> and perform the calculations on these smaller copies, so I calculate the homography matrix <code>H</code>, which maps <code>small1</code> into <code>small2</code>.
However, at the end, I would like to use calculate the homography matrix to project one full-size image <code>img1</code> onto the other the full-size image <code>img2</code>. </p>

<p>I thought I could simply transform the homography matrix <code>H</code> in the following way <code>H_full_size = A * H * A_inverse</code> where <code>A</code> is the matrix representing the scaling from <code>img1</code> to <code>small1</code> and <code>A_inverse</code> is its inverse. 
However, that does not work. If I apply <code>cv2.warpPerspective</code> to the scaled down image <code>small1</code> with <code>H</code>, everything goes as expected and the result (largely) overlaps with <code>small2</code>. If I apply <code>cv2.warpPerspective</code> to the full size image <code>img1</code> with <code>H_full_size</code> the result does not map to <code>img2</code>.</p>

<p>However, if I project the point matches (detected on the scaled down images) using <code>A</code> (using something like <code>projected_pts = cv2.perspectiveTransform(pts, A)</code>) and then I calculate <code>H_full_size</code> from these, everything works fine. </p>

<p>Any idea what I could be doing wrong here?</p>

<p>The way I see it, the problem is that homography applies a perspective projection which is a non linear transformation (it is linear only while homogeneous coordinates are being used) that cannot be represented as a normal transformation matrix. Multiplying such perspective projection matrix with some other transformations therefore produces undesirable results.</p>

<p>You can try multiplying your original matrix H element wise with:</p>

<p>S = [1,1,scale ; 1,1,scale ; 1/scale, 1/scale, 1]</p>

<p>H_full_size = S * H</p>

<p>where scale is for example 2, if you decreased the size of original image by 2.</p>

python opencv coordinate-transformation homography