Last Updated : 12 Jun, 2025
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.rotate() function is used to rotate images by multiples of 90 degrees. It is a simple and fast way to rotate an image in just one line of code. we use this image:
Example:
Python
import cv2
path = r'C:\Users\user\Desktop\geeks14.png'
src = cv2.imread(path)
rotated = cv2.rotate(src, cv2.ROTATE_90_CLOCKWISE)
cv2.imshow("90° Clockwise", rotated)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output
Explanation:
cv2.rotate(src, rotateCode[, dst])
Parameter:
Parameter
Description
src
The input image (as a NumPy array).
rotateCode
An enum value that defines the rotation direction.
dst(Optional)
The output image (usually ignored, since the function returns the image).
Returns: This function returns the rotated image.
Available rotateCode valuesOpenCV offers constants to rotate images by 90°, 180° or 270° without manual pixel manipulation. Below are the common rotation codes and their meanings:
Constant
Description
cv2.ROTATE_90_CLOCKWISE
Rotates the image 90 degrees clockwise.
cv2.ROTATE_180
Rotates the image 180 degrees.
cv2.ROTATE_90_COUNTERCLOCKWISE
Rotates the image 90 degrees counterclockwise (i.e., 270° clockwise).
ExamplesExample 1: In this example, we rotate the image upside down by rotating it 180 degrees.
Python
import cv2
path = r'C:\Users\user\Desktop\geeks14.png'
src = cv2.imread(path)
rotated = cv2.rotate(src, cv2.ROTATE_180)
cv2.imshow("180° Rotation", rotated)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output
Explanation:
Example 2: In this example, we rotate the image 270 degrees clockwise (which is equivalent to 90 degrees counterclockwise)
Python
import cv2
path = r'C:\Users\user\Desktop\geeks14.png'
src = cv2.imread(path)
rotated = cv2.rotate(src, cv2.ROTATE_90_COUNTERCLOCKWISE)
cv2.imshow("270° Clockwise", rotated)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output
Explanation:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4