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

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()

 

上一篇:Python报错module 'scipy.misc' has no attribute 'imsave' 或者'imread'


下一篇:解决from scipy.misc import imread中出现ImportError:No module named 'imread'