opencv
  1. opencv-image-rotation

Image Rotation - ( Image Basics with OpenCV )

Heading h2

Syntax

cv2.rotate(src, rotateCode)

Example

import cv2

# loading an image
img = cv2.imread("image.jpg")

# rotating the image by 90 degrees clockwise
rotated = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)

# displaying the original and rotated images
cv2.imshow("Original", img)
cv2.imshow("Rotated", rotated)
cv2.waitKey(0)

Output

The output is the original and rotated images displayed in separate windows.

Explanation

Image rotation is a common image processing operation used to change the orientation of an image. In OpenCV, image rotation can be achieved using the cv2.rotate() function. This function takes in the source image and the rotation code, which specifies the degree and direction of rotation.

In the above example, we load an image using cv2.imread() and then rotate it 90 degrees clockwise using the cv2.rotate() function with the cv2.ROTATE_90_CLOCKWISE code. The rotated image is then displayed using cv2.imshow().

Use

Image rotation is a common image processing operation used in various computer vision and deep learning applications. It is used to change the orientation of an image and correct image orientation problems caused by camera angle or image capture orientation.

Important Points

  • Image rotation is a common image processing operation used to change the orientation of an image
  • In OpenCV, image rotation can be achieved using the cv2.rotate() function
  • The function takes in the source image and the rotation code, which specifies the degree and direction of rotation
  • Common rotation codes include cv2.ROTATE_90_CLOCKWISE, cv2.ROTATE_90_COUNTERCLOCKWISE, and cv2.ROTATE_180

Summary

In conclusion, image rotation is an important image processing operation used in various computer vision and deep learning applications. In OpenCV, image rotation can be achieved using the cv2.rotate() function. The function takes in the source image and the rotation code, which specifies the degree and direction of rotation. Correct image orientation problems caused by camera angle or image capture orientation can be corrected using image rotation.

Published on: