Python OpenCV – cv2.rotate() method
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.rotate() method is used to rotate a 2D array in multiples of 90 degrees. The function cv::rotate rotates the array in three different ways.
Syntax: cv2.cv.rotate( src, rotateCode[, dst] )
Parameters: src: It is the image whose color space is to be changed.
rotateCode: It is an enum to specify how to rotate the array.
dst: It is the output image of the same size and depth as src image. It is an optional parameter.
Return Value: It returns an image.
Image used for all the below examples:
Example #1: Rotate by 90 degrees clockwise
Python3
import cv2
path = r 'C:\Users\user\Desktop\geeks14.png'
src = cv2.imread(path)
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_90_CLOCKWISE)
cv2.imshow(window_name, image)
cv2.waitKey( 0 )
|
Output:
Example #2: Rotate by 180 degrees clockwise
Python3
import cv2
path = r 'C:\Users\user\Desktop\geeks14.png'
src = cv2.imread(path)
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_180)
cv2.imshow(window_name, image)
cv2.waitKey( 0 )
|
Output:
Example #3: Rotate by 270 degrees clockwise
Python3
import cv2
path = r 'C:\Users\user\Desktop\geeks14.png'
src = cv2.imread(path)
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_90_COUNTERCLOCKWISE)
cv2.imshow(window_name, image)
cv2.waitKey( 0 )
|
Output:
Last Updated :
05 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...