1、等比例缩放
def resize_img():
'''
按照宽高比例等比例缩放图片
:return:
'''
import cv2
img_path = r"20201113200656_7.jpg"
img = cv2.imread(img_path)
height = img.shape[0]
width = img.shape[1]
if height > width:
ratio = width / height
new_img = cv2.resize(img, (width,int(ratio * height)), interpolation=cv2.INTER_CUBIC)
else:
ratio = height / width
new_img = cv2.resize(img, (int(ratio * width),height), interpolation=cv2.INTER_CUBIC)
print(0)
return new_img