# Revision history [back]

Loop & Zhang present a solution in this paper. They use a shearing transform to reduce the distortion introduced by the projective transform that mapped the epipoles to infinity (ie, that made the epipolar lines parallel). Consider the shearing transform

     | k1 k2 0 |
S =  | 0   1 0 |.
| 0   0 1 |


Let w and h be image width and height respectively. Consider the four midpoints of the image edges:

a = ((w-1)/2, 0, 1),
b = (w-1, (h-1)/2, 1),
c = ((w-1)/2, h-1, 1) and
d = (0, (h-1)/2, 1).


According to Loop & Zhang:

(...) we attempt to preserve perpendicularity and aspect ratio of the lines bd and ca

Let H be the rectification homography and let a' = Ha be a point in the affine plane by dividing through so that a' = 1 (note a' is the third component, ie, a' = (a', a', a')). Let

x = b' - d',
y = c' - a'


According to Loop & Zhang:

As the difference of affine points, x and y are vectors in the euclidean image plane. Perpendicularity is preserved when (Sx)^T(Sy) = 0, and aspect ratio is preserved if [(Sx)^T(Sx)]/[(Sy)^T(Sy)] = w²/h².

The real solution presents a closed-form:

k1 = (h²x² + w²y²)/(hw(xy - xy)) and
k2 = (h²xx + w²yy)/(hw(xy - xy))


up to sign (the positive is preferred).

This is the result after applying shearing S on the left image: Now the left and right images overlaped: Finally, OpenCV stereo method StereoBM can compute a reasonable result for disparity: 