Warping an image using affine and perspective transformations
In this recipe, we will review two main ways to geometrically transform images: affine and perspective warps. The first one is used to remove simple geometrical transformations such as rotations, scales, translations, and their combinations, but it can't turn converging lines into parallel ones. Here, perspective transformation comes into play. It aims to eliminate perspective distortions when two parallel lines converge in perspective views. Let's find out how to use all these transformations in OpenCV.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV version 3.3 (or greater) Python API package.
How to do it
You need to complete the following steps:
- Import the necessary modules, open an input image, and copy it:
import cv2 import numpy as np img = cv2.imread('../data/circlesgrid.png', cv2.IMREAD_COLOR) show_img = np.copy(img)
- Define two functions to implement the process of points selection :
selected_pts...