OpenCV Python Image Perspective Transform

original image - left and warped image - right

I wanted to learn OpenCV Perspective Transform. Tutorials that I found on the internet bit complex for me to really understand what it is all about. I have to read few tutorials before really understand it.

In layman term, perspective transform is taking a rectangle area from original image and re-project the cut rectangle to our defined size canvas.

To do this, you just need 4 corner pixel points and perspective transform will do all other pixels calculation automatically based on those 4 pixels points.

The Required Pixel Points

The corner pixels points must follow the order as shown in below image.

source pixels positions order
source pixels positions order

This is considered the source pixel points.

The destination points are where you want to re-project those source points into new plane.

The size of destination plane is:

width: 1000 pixels
height: 200 pixels

I just take the source rectangle width and height.

Image Used for the Perspective Transform

I used below image to do the perspective transform.

restaurant original image
restaurant original image

Code on Perspective Transform

Filename: Main.py

To run the program, type at the terminal

 

Folder Structure:

source code folder structure
source code folder structure

Reference

OpenCV Perspective Transform Youtube