0% found this document useful (0 votes)
4 views3 pages

CV Practical

The OpenCV library is utilized for computer vision applications, requiring imports of numpy and matplotlib for image handling and display. The document outlines various tasks such as loading images, converting color formats, reading grayscale images, cropping, changing pixel values, resizing images, and saving them. It emphasizes the importance of maintaining aspect ratio during resizing for model training purposes and provides references for further learning.

Uploaded by

aavaniragesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

CV Practical

The OpenCV library is utilized for computer vision applications, requiring imports of numpy and matplotlib for image handling and display. The document outlines various tasks such as loading images, converting color formats, reading grayscale images, cropping, changing pixel values, resizing images, and saving them. It emphasizes the importance of maintaining aspect ratio during resizing for model training purposes and provides references for further learning.

Uploaded by

aavaniragesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OpenCV library

The OpenCV library is designed to help us with computer vision application.


To use OpenCV library, it is necessary to import it as follows:

Note: We import numpy as we want to store the pixel values in the numpy array We import matplotlib to allow us to
display our images on the Jupyter notebook itself.

Initial settings required:


• Download the images in your system .
• Upload the image into the files of your current Colab Notebook.
This has to be repeated for all executions.

Task 1: Load the image file and display with labels.


Sample code:

Note :OpenCV represents the images in BGR as opposed to the RGB we expect. Since it is in the reverse
order, you tend to see the blue color in images.

Task 2: Load the image file and display in RGB.


Sample code for converting from BGR to RGB:
Task 3: Read the image as a grayscale image.

Task 4: Find the size of the image.

The numbers in your output shows the height ,width and the channels( RGB).

Task 4: Crop the flower into a square


When you want to focus on certain area of the image, either to process the image and get rid of non-relevant
parts, or to draw a bounding box around a certain area, our 'region of interest(ROI) can be cropped from
image .

Task 5: Changing pixel value.


Pixel values can be changed so that we can 'blank out' a portion from the images.
Task 6: Resizing the images.
Resizing images is important, especially when we want to train our model. When training a model, we want
all our images to have the same size and aspect ratio.

Note: The image is resized, but it is definitely distorted as we are not maintaining the aspect ratio. Not good
for our training purposes!

Task 7: Resizing images, maintaining aspect ratio.

Task 8: Saving images.


We can save our image using the imwrite function.

Take a look at your folder. Do you see the new file? Compare the size of the original and resized.

References:
• https://pyimagesearch.com/
• https://opencv.org/

You might also like