Rotation of image

From Lofaro Lab Wiki
Revision as of 23:14, 12 November 2014 by Kanik (Talk | contribs)

Jump to: navigation, search

We were doing translation where we were shifting our image according to the pixel we want. Rotation of image will rotate the image to some angle let’s say x. so x will represent by how many degrees we want to rotate our image. Let’s explain the concept of rotation using some code.


import cv2
import numpy as np
image = cv2.imread('hubo.jpg',0)
cv2.imshow("Original", image)
# get the dimensions of the image and calculate the center of the image
(h, w) = image.shape[:2]
center = (w / 2, h / 2)
# Rotate the image by 45 degrees
M = cv2.getRotationMatrix2D(center, 45, 1.0)
rotated = cv2.warpAffine(image, M, (w, h))
cv2.imshow("Rotated by 45 Degrees", rotated)
# Rotate our image by -90 degrees
M = cv2.getRotationMatrix2D(center, -90, 1.0)
rotated = cv2.warpAffine(image, M, (w, h))
cv2.imshow("Rotated by -90 Degrees", rotated)
cv2.waitKey(0)
cv2.destroyAllWindows()