美文网首页
OpenCV-Python 保存图像

OpenCV-Python 保存图像

作者: 翼徳 | 来源:发表于2019-04-04 11:04 被阅读0次

    OpenCV 版本:3.4.3
    编程语言:Python
    原文:https://docs.opencv.org/3.4.3/dc/d2e/tutorial_py_image_display.html

    可以用 cv.imwrite(filename, imgMat) 函数来保存图像。

    参数:

    • filename 是保存后的文件名;
    • imgMat 是要保存的图像数据;

    以下代码将会把图像以png格式保存到当前代码所在目录,示例:

    cv.imwrite('messigray.png', img)
    

    完整示例:

    import cv2 as cv
    
    img = cv.imread('/Users/scott/Documents/opencv-test-01.bmp', cv.IMREAD_UNCHANGED)
    cv.imshow('tmp_window', img)
    
    # 64位的机器需要加 & 0xFF
    k = cv.waitKey(10000) & 0xFF
    
    if k == 27:         # wait for ESC key to exit
        print('press key ESC')
        cv.destroyAllWindows()
    elif k == ord('s'): # wait for 's' key to save and exit
        print('press key s')
        cv.imwrite('messigray.png',img)
        cv.destroyAllWindows()
    

    相关文章

      网友评论

          本文标题:OpenCV-Python 保存图像

          本文链接:https://www.haomeiwen.com/subject/dcpabqtx.html