附代码如下:
import cv2 as cv import numpy as np def resize(): src = cv.imread("D:/matplotlib/0.jpg") cv.imshow("input",src) h, w = src.shape[:2] print(h,w) dst = cv.resize(src,(w//2,h//2),interpolation = cv.INTER_LINEAR) cv.imshow("output",dst) cv.waitKey(0) cv.destroyAllWindows() resize()
运行结果:
代码解释:
import cv2 as cv import numpy as np def resize(): src = cv.imread("D:/matplotlib/0.jpg") #读取图像 cv.imshow("input",src) #显示图像 h, w = src.shape[:2] #输出图像属性 print(h,w) dst = cv.resize(src,(w//2,h//2),interpolation = cv.INTER_LINEAR) #缩小图像并进行双线性插值计算 cv.imshow("output",dst) #显示插值后的结果 cv.waitKey(0) cv.destroyAllWindows() resize()