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