September 2015
Beginner to intermediate
296 pages
5h 57m
English
In this section, we will see how to rotate a given image by a certain angle. We can do it using the following piece of code:
import cv2
import numpy as np
img = cv2.imread('images/input.jpg')
num_rows, num_cols = img.shape[:2]
rotation_matrix = cv2.getRotationMatrix2D((num_cols/2, num_rows/2), 30, 1)
img_rotation = cv2.warpAffine(img, rotation_matrix, (num_cols, num_rows))
cv2.imshow('Rotation', img_rotation)
cv2.waitKey()If you run the preceding code, you will see an image like this:

In order to understand this, let's see how we handle rotation mathematically. Rotation is also a form of transformation, and we can ...