opencv-python-学习笔记一(图像的读取与写入)

import numpy as np
import cv2 as cv
# 读入图像
# cv.IMREAD_COLOR  cv.IMREAD_GRAYSCALE  cv.IMREAD_UNCHANGED cv2.COLOR_BGR2RGB
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()

 

posted @ 2019-07-06 11:52  少灬儿郎  Views(740)  Comments(0Edit  收藏  举报