O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scaling

In order to resize the image, OpenCV has a resize() function, which takes the image, dimensions, and interpolation algorithm as input. Various interpolation algorithms can be used to interpolate the new pixel values. The following are the interpolation algorithms, which can be used to resize the image:

  • cv2.INTER_AREA: This algorithm is preferred for shrinking the image
  • cv2.INTER_CUBIC: This algorithm is preferred for zooming (slow)
  • cv2.INTER_LINEAR: This algorithm is preferred for zooming
  • cv2.INTER_LINEAR: This is the default algorithm

The following is an example of resizing an image:

>>> import cv2>>> img = cv2.imread("image.jpg")>>> r,c = img.shape[:2]>>> new_img = cv2.resize(img, (2*r,2*c), interpolation = cv2.INTER_CUBIC)>>> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required