A homography is a transformation that maps points from one plane to another, typically in computer vision and image processing applications. It is a projective transformation that preserves straight lines. In simpler terms, it can describe the relationship between two images.

Mathematically, the homography is represented as a 3×3 matrix. If (x,y) are the coordinates of a point in one image, and (x’,y’) are the coordinates of the corresponding point in another image, then the relationship between the two can be expressed as:

Where hij‚Äč are the elements of the homography matrix. This matrix can be computed using corresponding points in the two images, typically through techniques like direct linear transformation (DLT) or least squares estimation.

Homographies are used in various computer vision tasks such as image registration, panorama stitching, object recognition, and augmented reality. They allow for the alignment and transformation of images taken from different perspectives, enabling analysis and manipulation of visual data.


We have one image where we want to change the perspective in order to position it in another image. In this case, we want to change the perspective of image1 so it fits in the computer screen.

These images are contained inside the media folder.


(libraries to install):

pip install numpy
pip install cv2


Inside the folder in the CMD, you must execute:

python 01_homography.py

Select one point of image1, and the new position you want it to have in image2 and press ‘s’. The points will change to green when they are saved:

Do this with four different points. In this case, we mark the four corners of the wallpaper and its respective four corners in the computer.

Press h in order to see the plan view; that is the perspective transformation that will be applied to the image:

Then, in order to see the images combined, press m.


To receive the “Homography” code, please fill out the form below.

Upon submission, we’ll promptly send you the ZIP file containing the code you requested. Please ensure you’ve checked your spam folder if you don’t receive our email shortly after submitting your request.