Python OpenCV - cv2.rotate() method Last Updated : 12 Jun, 2025 Comments Improve Suggest changes Like Article Like Report 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() OutputExplanation:cv2.imread() loads the image from the given file path and cv2.rotate() rotates it using a specified code like cv2.ROTATE_90_CLOCKWISE.cv2.imshow() displays the image in a window, cv2.waitKey(0) waits for a key press and cv2.destroyAllWindows() closes the window.Syntaxcv2.rotate(src, rotateCode[, dst])Parameter:ParameterDescriptionsrcThe 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 Descriptioncv2.ROTATE_90_CLOCKWISE Rotates the image 90 degrees clockwise.cv2.ROTATE_180Rotates 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() OutputExplanation:cv2.imread() loads the image from the given file path and cv2.rotate() rotates it using the cv2.ROTATE_180 code, which flips the image upside down.cv2.imshow() displays the image in a window, cv2.waitKey(0) waits for a key press and cv2.destroyAllWindows() closes the window afterward.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() OutputExplanation:cv2.imread() loads the image from the given file path and cv2.rotate() rotates it using the cv2.ROTATE_90_COUNTERCLOCKWISE code, which is equivalent to a 270-degree clockwise rotation (or 90 degrees to the left).cv2.imshow() displays the rotated image, cv2.waitKey(0) pauses for a key press and cv2.destroyAllWindows() closes the display window. Comment More infoAdvertise with us D divyamohan123 Follow Improve Article Tags : Python Image-Processing OpenCV Python-OpenCV Practice Tags : python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 6 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 6 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like