Skip to content

Instantly share code, notes, and snippets.

@vicotrbb
Last active July 2, 2020 01:47
Show Gist options
  • Save vicotrbb/297b472626942e038ee899600f1350a9 to your computer and use it in GitHub Desktop.
Save vicotrbb/297b472626942e038ee899600f1350a9 to your computer and use it in GitHub Desktop.
import cv2 # openCV
import numpy as np
def image_resize(image, width = None, height = None):
img = cv2.imread(image)
dim = None
(h, w) = image.shape[:2]
if width is None:
r = height / float(h)
dim = (int(w * r), height)
else:
r = width / float(w)
dim = (width, int(h * r))
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
return resized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment