1. 改变图像的大小-cv2.resize()
函数原型:cv2.resize(src, dst, Size, fx, fy, interpolation)
参数说明:1. src 输入图片 2. dst 输出图片 3.size 输出图片的大小 4. fx、fy:沿水平轴、垂直轴的缩放因子(宽度、高度) 5.插入方式,默认为INTER_LINEAR.
插入方式interpolation有以下几种:
INTER_NEAREST |
最近邻插值 |
INTER_LINEAR |
双线性插值(默认设置) |
INTER_AREA |
使用像素区域关系进行重采样。 |
INTER_CUBIC |
4x4像素邻域的双三次插值 |
INTER_LANCZOS4 |
8x8像素邻域的Lanczos插值 |
代码如下:
def resize_demo(image):
print("Origin size:", image.shape)
# 第一种方法:通过fx,fy缩放因子
res = cv.resize(image, None, fx=1, fy=3, interpolation