IMAGE ROTATION
USING OPENCV
Presented By :- Sahil Sameer Suriya(1DA23MC036)
Contents
•Introduction
•Opencv-prerequisites
•Basic functions with images
•Displaying an image
•Computing a matrix for rotating images with opencv
•Applying geometric transformations with
opencv's cv2.Warpaffine
•Applications
Introduction
•OpenCV stands for open-source computer vision.
•It is basically a powerful and reliable library for performing
image processing and computer vision tasks.
•A library in programming refers to a set/package of pre-
defined functions.
•This library is popular for its easiness and performance.
•This library is available in both python and C++ with functions
having different syntaxes.
•Some of the common tasks done using OpenCV includes face
detection, image processing, video processing and so on ...
Opencv-prerequisites
•The key feature in python version of OpenCV is that the
functions are obvious. This means that the meaning of the
function is known from the name of the function.
•OpenCV in python language is known as cv2. This is the name
of the library we have use.
•This library may not have been pre-installed in your IDE.
Hence it is essential to install the library on the prompt.
•Windows-> Search bar-> Command Prompt-> Run as
Administrator.
•After this, you must type pip install opencv-python
•Opencv is installed in your system.
Basic functions with images
•Since the library is installed in the system, we can use them by
simply importing them by the command import cv2
•So now we can do a lot of interesting stuffs on images. But
before that it is essential to load/read the image in the IDE.
•This is done using the imread function.
•cv2.imread(image filename, mode)
•The above is the syntax for the imread function, and the role is
obvious, it is going to read the image from the system to the
IDE.
Displaying an image
•Assuming that we have applied a suited image processing technique
over our read image, it is essential to show the image.
•We have to display the image on which we have performed our
processing on. For this, there is a function in OpenCV called as
imshow.
•cv2.imshow("image name", image)
•The first argument is the name that we want to keep for the image.
It is essential that we give the name within single or double quotes.
•The second argument is the image, this is the image which has been
read by the imread function.
•We can store the read image in a temporary variable and then use it
in the imshow function.
Computing a matrix for rotating
images with opencv
The cv2.getRotationMatrix2D function is a crucial component in
OpenCV for rotating images. It computes a rotation matrix that
can be used to rotate an image by a specified angle around a
given center point, with an optional scale factor.
Functionality
The cv2.getRotationMatrix2D function takes three parameters:
•Center: The center point of rotation, specified as a tuple of
two values (x, y).
•Angle: The angle of rotation in degrees.
•Scale: The scale factor, which can be used to resize the image
during rotation.
Applying geometric
transformations with
opencv's cv2.Warpaffine
The cv2.warpAffine function is a powerful tool in OpenCV for applying
geometric transformations to images. It takes an input image, a
transformation matrix, and output image dimensions as parameters,
and returns the transformed image.
Parameters
•The cv2.warpAffine function takes three parameters:
•Input Image: The original image to be transformed.
•Transformation Matrix: A 2x3 matrix that represents the affine
transformation. This matrix can be obtained using functions
like cv2.getRotationMatrix2D, cv2.getAffineTransform,
or cv2.getPerspectiveTransform.
•Output Image Dimensions: A tuple of two values (width,
height) that specifies the size of the output image.
Applications
Image Alignment
Image alignment is the process of aligning multiple images of
the same scene taken from different viewpoints or at different
times. This is useful in applications such as:
•Panorama stitching: Aligning multiple images to create a
seamless panorama.
•Image mosaicing: Combining multiple images to create a
larger image.
•Object recognition: Aligning images to recognize objects or
scenes.
Object Recognition
Object recognition involves identifying objects within an image
or video stream. Preprocessing images using affine
transformations can improve feature detection and recognition
accuracy. For example:
•Image normalization: Rotating and scaling images to a
standard size and orientation can improve feature detection.
•Image denoising: Applying affine transformations to remove
noise and artifacts can enhance feature detection.
•Object detection: Applying affine transformations to detect
objects at different orientations and scales.