Я знаю, что вы запрашиваете только cv2.resize, но вы можете использовать библиотеку imutils , которая выполняет для вас часть кода отношения.
import imutils
resized = imutils.resize(img, width=newwidth)
Внутри imutils:
dim = None
(h, w) = image.shape[:2]
# check to see if the width is None
if width is None:
# calculate the ratio of the height and construct the
# dimensions
r = height / float(h)
dim = (int(w * r), height)
# otherwise, the height is None
else:
# calculate the ratio of the width and construct the
# dimensions
r = width / float(w)
dim = (width, int(h * r))
# resize the image
resized = cv2.resize(image, dim, interpolation=inter)