OpenCV is a Python module specifically made for image processing, rotating, filtering, and manipulating. We can use OpenCV to rotate images in various degrees including 30, 60, 90, 120, 180, and so on. In this article, we will especially learn to rotate image 90 in OpenCV. We will first install the OpenCV, then import the module, and will learn how to use the cv2.rotate() method to rotate image 90.
Rotate Images 90, 270, and 180 in OpenCV
OpenCV is a very popular module used for image processing in Python. It makes the process of filtering, rotation, cropping, and editing very simple. These all functionalities can be achieved by just importing the OpenCV module and then calling each of the functions. Similarly, an image can be rotated by calling the function cv2.rotate(). We will now see, how we can use this function to rotate images 90, 270, and 180 degrees.
Before going to the implementation part, make sure you have installed the OpenCV module on your system. Once the installation is successful, then import the module.
# importing cv2
import cv2
We will rotate the following image in different directions:

Now, let us see how we can use the cv2.rotate() method to rotate an image at different angles:
Rotate the Image 90 Degrees Using cv2.rotate()
To rotate the image at 90 degrees, we have to specify two important parameters. The first parameter is the degree and the second parameter shows the direction of the rotation. It can either be clockwise or anti-clockwise. First, we will rotate the image at 90 degrees in a clockwise direction.
# importing cv2
import cv2
# Reading image in opencv
src = cv2.imread('cricket image.jpeg')
# Window name
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_90_CLOCKWISE)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)

As shown above, the cv2.ROTATE_90_CLOCKWISE method helps us to rotate the image 90 degrees clockwise. Similarly, to rotate, the image anti-clockwise, you need to change the clockwise to anti-clockwise as shown below:
# Reading image in opencv
src = cv2.imread('cricket image.jpeg')
# Window name
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_90_COUNTERCLOCKWISE)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)
This will help you to rotate the image in an anti-clockwise direction.
Rotate the Image at 180 and 270 Degrees using cv2.rotate() Method
Rotating the image to any other degree is very similar to rotating the image to 90 degrees. All we need is to change the degree of angle. Let us first rotate the image to 180 degrees using the same method:
# importing cv2
import cv2
# Reading image in opencv
src = cv2.imread('cricket image.jpeg')
# Window name
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_180)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)
Now, we will do a similar process to rotate the image to 270 degrees as well.
# importing cv2
import cv2
# Reading image in opencv
src = cv2.imread('cricket image.jpeg')
# Window name
window_name = 'Image'
image = cv2.rotate(src, cv2.ROTATE_270)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)
Congratulations, you have successfully learned how to rotate images 90, 180, and 270 degrees using the OpenCV module.
Final Thoughts
We all know OpenCV is a very powerful open-source Python module that offers many powerful functions to manipulate and process images. One such popular method is cv2.rotate() which allows us to rotate the image at different degrees. In this short tutorial, we learned how we can rotate an image 90, 180, and 270 degrees.