OpenCV Image Rotation in Python

In this Python OpenCV article we are going to talk about Image Rotation in OpenCV, so we can

use cv2.rotate() function for rotating an image in OpenCV and there are three constant types of

rotation that you can pass as parameter in the function. so these are the constants.

 

  • cv2.ROTATE_90_CLOCKWISE
  • cv2.ROTATE_90_COUNTERCLOCKWISE
  • cv2.ROTATE_180

 

 

Read Image Smoothing Techniques in OpenCV

1: OpenCV Averaging Image Blurring in Python

2: OpenCV Gaussian Blurring for Images in Python

3: OpenCV Median Blurring for Images in Python

4: OpenCV Smooth Image with Bilateral Filtering

 

 

 

 

 

So now this is the complete source code for OpenCV Image Rotation in Python 

 

 

 

 

 

This  line of code is used for reading of the image, make sure that you have added an image

in your working directory.

 

 

 

 

So in here we have used cv2.rotate() function and we have added our three types of rotation.

 

 

 

 

 

Because we are going to show our images in Matplotlib, so Matplotlib uses RGB (Red, Green, Blue)

color system, and OpenCV uses BGR (Blue, Green, Red) color system, we need to convert the BGR

color to RGB. if we don’t do this there will be messed up in the color.

 

 

 

 

Notecv2.waitKey() is a keyboard binding function. Its argument is the time in milliseconds.

the function waits  specified milliseconds for any keyboard event. If you press any key in that

time, the program continues. If 0 is passed, it waits indefinitely for a key stroke.

 

 

 

 

 

So now run the complete code and this will be the result.

OpenCV Image Rotation in Python
OpenCV Image Rotation in Python

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×