标签:ons otto 需要 tuple tom 矩形 highlight min keep
参考链接:https://www.jianshu.com/p/3092835eab61
def resize_img_keep_ratio(img_name,target_size): img = cv2.imread(img_name) old_size= img.shape[0:2] #ratio = min(float(target_size)/(old_size)) ratio = min(float(target_size[i])/(old_size[i]) for i in range(len(old_size))) new_size = tuple([int(i*ratio) for i in old_size]) img = cv2.resize(img,(new_size[1], new_size[0])) pad_w = target_size[1] - new_size[1] pad_h = target_size[0] - new_size[0] top,bottom = pad_h//2, pad_h-(pad_h//2) left,right = pad_w//2, pad_w -(pad_w//2) img_new = cv2.copyMakeBorder(img,top,bottom,left,right,cv2.BORDER_CONSTANT,None,(0,0,0)) return img_new if__name__==‘main‘: img = ‘‘ target_size=[448,112] resize_img_keep_ratio()
作者:涂山容容
Python opencv resize图片并保存原有的图像比例
标签:ons otto 需要 tuple tom 矩形 highlight min keep
原文地址:https://www.cnblogs.com/wangyarui/p/12058445.html