python opencv 等比例调整(缩放)图片分辨率大小代码 cv2.resize()

在这里插入图片描述

# -*- coding: utf-8 -*-
"""
@File    : 200113_等比例调整图像分辨率大小.py
@Time    : 2020/1/13 13:38
@Author  : Dontla
@Email   : [email protected]
@Software: PyCharm
"""
import cv2


def img_resize(image):
    height, width = image.shape[0], image.shape[1]
    # 设置新的图片分辨率框架
    width_new = 1280
    height_new = 720
    # 判断图片的长宽比率
    if width / height >= width_new / height_new:
        img_new = cv2.resize(image, (width_new, int(height * width_new / width)))
    else:
        img_new = cv2.resize(image, (int(width * height_new / height), height_new))
    return img_new


img = cv2.imread('lena_test.jpg')
img_new = img_resize(img)
print(img_new.shape)
cv2.imshow('win', img_new)
cv2.waitKey(0)

结果:
在这里插入图片描述
参考文章1:OpenCV修改图片大小

参考文章2:python opencv cv2.resize()函数

发布了747 篇原创文章 · 获赞 28 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/Dontla/article/details/103957078