opencv笔记—图像缩放

图像缩放:
图像缩放即对图像的大小进行调整,即放大或者缩小

cv2.resize(src,dsize,fx=0,fy=0,interpolation=cv2.INTER_LINEAR)

参数:
在这里插入图片描述

实现代码:

import cv2 as cv
import matplotlib.pyplot as plt
# 中文显示配置
plt.rcParams['font.sans-serif']=['SimHei']      # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False        # 用来正常显示负号

# 载入图像
img0 = cv.imread('img/img1.jpeg')

# 图像缩放
# 绝对尺寸缩放
rows, cols = img0.shape[:2]
res0 = cv.resize(img0,(3*cols,3*rows),interpolation=cv.INTER_CUBIC)
# 相对尺寸缩放,若用相对缩放则第二个参数要设置为None
res1 = cv.resize(img0, None, fx = 0.5, fy = 0.5)

# 查看图像大小
print(res0.shape)
print(res1.shape)
print(img0.shape)

# 图像显示
fig, axes = plt.subplots(nrows=1,ncols=3,figsize=(10,8),dpi=100)
axes[0].imshow(res0[:,:,::-1])
axes[0].set_title("绝对尺度放大")
axes[1].imshow(res1[:,:,::-1])
axes[1].set_title("相对尺度缩小")
axes[2].imshow(img0[:,:,::-1])
axes[2].set_title("原图")
plt.show()

运行结果:
在这里插入图片描述cv小白,望大佬指点

猜你喜欢

转载自blog.csdn.net/weixin_45666249/article/details/114944496