import cv2 as cv
# 读入原图片
img = cv.imread('C:/Users/zhoujun/Desktop/12.jpg')
# 打印出图片尺寸
print(img.shape)
# 将图片高和宽分别赋值给x,y
x, y = img.shape[0:2]
# 显示原图
cv.imshow('OriginalPicture', img)
# 缩放到原来的二分之一,默认输出尺寸格式为(宽,高)
img_test1 = cv.resize(img, (int(y / 2), int(x / 2)))
cv.imshow('resize1', img_test1)
cv.waitKey()
# 最近邻插值法缩放到原来的四分之一
img_test2 = cv.resize(img, (0, 0), fx=0.25, fy=0.25, interpolation=cv.INTER_NEAREST)
cv.imshow('resize2', img_test2)
cv.waitKey()
#双线性插值(默认设置)缩放图片
img_test3 = cv.resize(img, (0, 0), fx=0.5, fy=0.25, interpolation=cv.INTER_LINEAR)
cv.imshow('resize3', img_test3)
cv.waitKey()
#使用像素区域关系进行重采样缩小
img_test4 = cv.resize(img, (0, 0), fx=0.25, fy=0.5, interpolation=cv.INTER_AREA)
cv.imshow('resize4', img_test4)
cv.waitKey()
# cv.destroyAllWindows()
#4x4像素邻域的双三次插值缩放
img_test5 = cv.resize(img, (0, 0)