OpenCV 版本:3.4.3
編程語言:Python
原文:https://docs.opencv.org/3.4.3/dc/d2e/tutorial_py_image_display.html
可以用 cv.imwrite(filename, imgMat)
函數(shù)來保存圖像。
參數(shù):
- filename 是保存后的文件名捏悬;
- imgMat 是要保存的圖像數(shù)據(jù)撞蚕;
以下代碼將會(huì)把圖像以png格式保存到當(dāng)前代碼所在目錄,示例:
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位的機(jī)器需要加 & 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()