Python Opencv等比例缩放图片
前言
前提条件
相关介绍
实验环境
等比例缩放图片
代码实现
import os
import cv2
path = 'myblog.png' # 获取文件路径
ori_img = cv2.imread(path) # 读取图片
print(ori_img.shape)
height, width = ori_img.shape[:2] # 原始分辨率
pix = 400
# 等比例缩放到pix=400
scale = pix / height
# 缩放后分辨率
height = pix
width = int(width * scale)
img = cv2.resize(ori_img, (width, height))
print(img.shape)
cv2.imwrite('res_'+path, img)
print('End!')
输出结果