import numpy as np import cv2 as cv # 读入图像 # cv.IMREAD_COLOR cv.IMREAD_GRAYSCALE cv.IMREAD_UNCHANGED img = cv.imread('4.jpg', cv.IMREAD_COLOR) # 创建窗口 # cv.WINDOW_AUTOSIZE cv.WINDOW_NORMAL cv.namedWindow('image', cv.WINDOW_NORMAL) # 显示图像 cv.imshow('image', img) # 等待键盘输入事件 k = cv.waitKey(0) & 0xFF if k == 27: # wait for ESC key to exit # 销毁窗口 cv.destroyAllWindows() elif k == ord('s'): # wait for 's' key to save and exit # 保存图像 cv.imwrite('messigray.png', img) cv.destroyAllWindows()