图片的读取保存
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('image.jpg',0)
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
#读取的图片映射到窗口上
cv2.imshow('image',img)
#等待时间,0:一直等待直到按键盘键后执行后续代码,
k = cv2.waitKey(0)
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
#保存图片
cv2.imwrite('messigray.png',img)
cv2.destroyAllWindows()
使用matplotlib
#matplotlib绘制RGB,但cv2是BGR
#使用双三次插值算法(bicubic interpolation)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()