| import cv2 | |
| def resize_image(image, width=None, height=None): | |
| if width is None and height is None: | |
| return image | |
| (h, w) = image.shape[:2] | |
| if width is None: | |
| ratio = height / float(h) | |
| width = int(w * ratio) | |
| else: | |
| ratio = width / float(w) | |
| height = int(h * ratio) | |
| return cv2.resize(image, (width, height)) | |