Search⌘ K
AI Features

Crop and Resize

Explore how to find image dimensions and maintain aspect ratio while resizing images in OpenCV. Understand the coordinate system used for cropping images and apply cropping by selecting pixel ranges. This lesson helps you master essential image editing skills useful for computer vision tasks.

1.

What do you think will happen if we try to read multiple images of a large size ?

Show Answer
Did you find this helpful?

So, what’s the solution?

To solve this issue, we resize the large images into smaller ones.

Find the dimensions of the image

To find the dimensions of the image, we use the img.shape method of the OpenCV library. Here, img is the object we’ve stored the image in. Let’s run the program to find the dimensions of the image:

Python 3.8
# Import library
import cv2
# Loading an image
img = cv2.imread(r"/usercode/image.jpg")
print(img.shape)

In the output, the first parameters are the height and width, respectively. The third parameter is the number of ...