import cv2 as cv
import numpy as np # 图片缩放
img = cv.imread('../images/moon.jpg', flags=1) # flags=1读取为彩色,flags=0读取为灰度
cv.imshow('i', img)
h, w, channel = img.shape # 以行列形式存储, 第几行到第几行为图像高度
dst_h = int(h*0.5)
dst_w = int(w*0.5)
# 最近邻域差值 双线性插值 像素关系重采样 立方差值
dst = cv.resize(img, (dst_w, dst_h)) # 默认双线性差值
cv.imshow('img', dst)
cv.waitKey(0)
关于这几个差值
https://blog.csdn.net/woainishifu/article/details/53260546
通过矩阵变换进行缩放
import cv2 as cv
import numpy as np # 图片缩放
img = cv.imread('../images/moon.jpg', flags=1) # flags=1读取为彩色,flags=0读取为灰度
h, w = img.shape[:2]
mat_shift = np.float32([[0.5, 0, 0], [0, 0.5, 0]]) # 缩放矩阵
dst = cv.warpAffine(img, mat_shift, (int(w/2), int(h/2)))
cv.imshow('img1', img)
cv.imshow('img2', dst)
cv.waitKey(0)