Uses of resizing and cropping images

Sometimes, we have to crop or resize our images. We might want to crop an image to make it more appealing for an Instagram post. Or, we might want to meet the image size and dimension criteria for an online form we have to fill out

Normally, we use editing software to edit images. However, if we have a large number of pictures to crop or resize, it can be very difficult to edit them all. The solution is to use OpenCV to edit all those pictures instantly. This can be very useful in photo studios, passport offices, and other governmental offices.

Steps to follow

We'll adopt the following steps to resize and crop images:

  1. Define the header files and namespaces.

  2. Declare variables for the original image, img, cropped image, croppedImg, and resized image, resizedImg.

  3. Read the image and store it in img.

The code based on the steps above is given below:

Get hands-on with 1400+ tech skills courses.