Image Rotation
Image rotation is a common image processing routine with applications in matching, alignment, and other image-based algorithms, in image rotation the image is rotated by a definite angle. It is used extensively in data augmentation, especially when it comes to image classification.
Python3
import numpy as np import cv2 as cv img = cv.imread( 'girlImage.jpg' , 0 ) rows, cols = img.shape M = np.float32([[ 1 , 0 , 0 ], [ 0 , - 1 , rows], [ 0 , 0 , 1 ]]) img_rotation = cv.warpAffine(img, cv.getRotationMatrix2D((cols / 2 , rows / 2 ), 30 , 0.6 ), (cols, rows)) cv.imshow( 'img' , img_rotation) cv.imwrite( 'rotation_out.jpg' , img_rotation) cv.waitKey( 0 ) cv.destroyAllWindows() |
We have used the get rotation matrix function to define the parameter required in the warpAffine function to tell the function to make a matrix that can give a required rotation angle( here it is 30 degrees) with shrinkage of the image by 40%.
img_rotation = cv.warpAffine(img, cv.getRotationMatrix2D((cols/2, rows/2), 30, 0.6), (cols, rows))
Output:
Image Transformations using OpenCV in Python
In this tutorial, we are going to learn Image Transformation using the OpenCV module in Python.
Contact Us