def resize_by_short_edge(img, size):
if isinstance(img, str):
img_path = img
img = cv2.imread(img_path, cv2.IMREAD_ANYCOLOR)
if img is None:
raise ImageNotFound("Image read None from path ", img_path)
if size < 1:
return img
h, w = img.shape[0], img.shape[1]
if h < w:
scale = w / float(h)
new_width = int(size * scale)
img = cv2.resize(img, (new_width, size))
else:
scale = h / float(w)
new_height = int(size * scale)
img = cv2.resize(img, (size, new_height))
return img
评论列表
文章目录