OpenCV-Python 保存图像

2019-04-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) 函数来保存图像。

参数:

以下代码将会把图像以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()
上一篇下一篇

猜你喜欢

热点阅读