Difference between revisions of "Rotation of image"
(Created page with "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 repre...") |
|||
Line 1: | Line 1: | ||
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. | 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 | + | <nowiki>import cv2 |
import numpy as np | import numpy as np | ||
image = cv2.imread('hubo.jpg',0) | image = cv2.imread('hubo.jpg',0) | ||
Line 19: | Line 19: | ||
cv2.waitKey(0) | cv2.waitKey(0) | ||
cv2.destroyAllWindows() | cv2.destroyAllWindows() | ||
− | + | </nowiki> |
Revision as of 23:08, 12 November 2014
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()