How to do Affine Transform in OpenCV Python

You can do affine transform using OpenCV Python by following the given steps. I highly recommend you get the “Computer Vision: Models, Learning, and Inference Book” to learn Computer Vision.

How to do Affine Transform in OpenCV Python
How to do Affine Transform in OpenCV Python

Step 1

Import the required libraries. If OpenCV is not installed in your system then first install it using This Method.

Python

Step 2

Now Read the Image. The image should be in the current working directory. Otherwise, mention the location of the image.

Python

Step 3

Now make two variables rows and cols. Use these two variables to make the final points of the required image.

Python

Step 4

First, make an affine_matrix using the function cv2.getAffineTransform. Then apply the matrix to the image using the function cv2.warpAffine.

Python

Step 5

Now display both images.

Python
Cat
Affine Transformation

Leave a Comment

Your email address will not be published.