import cv2 if __name__ == '__main__': img = cv2.imread(r'C:\Users\Administrator\Desktop\img1791.png') height, width = img.shape[:2] #缩小图片 size = (int(width*0.5), int(height*0.5)) shrink = cv2.resize(img, size, interpolation = cv2.INTER_AREA) cv2.imshow("缩小", shrink) cv2.imwrite(r'C:\Users\Administrator\Desktop\img1.png', shrink) #放大图片 fx = 1.6 fy = 1.2 enlarge = cv2.resize(img, (0, 0), fx = fx, fy = fy, interpolation = cv2.INTER_CUBIC) cv2.imshow("放大", enlarge)