python - 如何直接保存图像而不是通过对话框?
问题描述
当我按下 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()
解决方案
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.
推荐阅读
- javascript - 何时更喜欢 Javascript 函数构造函数而不是类?
- jenkins - 从 jenkins 更新 webdriver-manager 期间下载 geckodriver 时出错
- python - 链式模运算的最大值
- zabbix - 有没有办法在脚本中不提供用户名和密码的情况下登录 zabbix API
- android - 构建 QT Android 应用程序:..i686-linux-android-g++:没有这样的文件或目录
- spring - Spring-boot:使用 mvn 激活多个配置文件
- javascript - 滑动特定位置的详细信息应该存储在本地存储中吗?
- java - 如何知道元素是否包含命名空间(xmlns)?
- javascript - 使用图像之间的适当间距自定义 Slick 滑块设计
- wordpress - woocommerce_update_product 操作 – 每次产品更新仅触发一次