Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OpenCV resize (rescale) images

  • shape

  • resize

  • INTER_AREA

  • To reduce the computation power needed to process the image (or video)

import cv2 as cv
import sys

if len(sys.argv) != 3:
    exit(f"Usage: {sys.argv[0]} FILENAME SCALE  where scale is 0.75 or some similar number between 0 and 1")

filename = sys.argv[1]
scale = float(sys.argv[2])

original = cv.imread(filename)
cv.imshow('Original', original)

height, width, colors = original.shape
new_height = int(height * scale)
new_width = int(width * scale)

resized = cv.resize(original, (new_width, new_height), interpolation=cv.INTER_AREA)
cv.imshow('Resized', resized)
cv.waitKey(0)
  • Works on images, videos, live videos

  • Try to resiz the image to be larger than the original using either INTER_AREA or INTER_LINER or INTER_CUBIC.

  • Cubic is slower but better quality