The purpose of rectification is to warp an image to “correct” it - in our case, we rectify shapes that are rectangles but do not appear as such in an image. To do this, we apply a homography matrix H, where H is computed using the initial correspondences and the target coordinates. We want to satisfy the equation p’=Hp, where p and p’ refer to the coordinates of the source and destination coordinates, respectively. Because we have more correspondences than required, we use least squares to minimize error.
The matrix H can be computed in the following way:
Example 1: Book rectified to rectangularize the front cover
Example 2: Photo rectified to rectangularize the photo inside the frame