首页 > 解决方案 > 如何直接保存图像而不是通过对话框?

问题描述

当我按下 Ctrl+s 时,我正在尝试保存图像。但不是直接保存图像,而是打开“另存为”对话框,如所附图像所示。我希望我的代码在按下 Ctrl+s 时直接保存为tiger2.png。

   image = cv2.imread('tiger.jpg',0) #Reading the image

   cv2.imshow('image',image)
   k = cv2.waitKey(0)

   if k == 27:           #Closing window when user presses ESC key
       cv2.destroyAllWindows()

   elif k == 19:         #Saving image when user presses Ctrl+s

       cv2.imwrite('tiger2.png',image)
       cv2.destroyAllWindows()

标签: pythonopencv

解决方案


The problem seems to be that Ctrl + s is a built in function in cv2.imshow() which opens a save dialog: https://github.com/opencv/opencv/issues/5071

if you change

elif k == 19:

to something like

elif k == 115: #Save when pressing s

this will work as you intend.


推荐阅读