关于python下cv.waitKey无响应的原因及解决方法


Posted in Python onJanuary 10, 2019

按下键的时候,焦点要落在窗口上,不能落在cmd窗口上。

另外,一般在imshow()后要使用waitKey(),给图像绘制留下时间,不然窗口会出现无响应情况,并且图像无法显示出来。

int waitKey(int delay=0) 
- 延时delay = 0 函数则延时无限长,必须有键按下才继续执行。 
- 延时delay > 0 函数返回值为按下的键的ASCII码值,超时则返回-1。
OpenCV: waitKey
waitKey 
Waits for a pressed key.
C++: int waitKey(int delay=0) 
Python: cv2.waitKey([delay]) → retval

Parameters: delay ? Delay in milliseconds. 0 is the special value that means “forever”.
The function waitKey waits for a key event infinitely (when \texttt{delay}\leq 0 ) or for delay milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is running on your computer at that time. It returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed.
Note 
This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.
Note 
The function only works if there is at least one HighGUI window created and the window is active. If there are several HighGUI windows, any of them can be active.

也就是说必须在有窗口显示的情况下,waitKey才有作用,否则无效。

比如调用cv.waitKey(0),如果此时没有活动的窗口,该函数立刻返回-1

以上这篇关于python下cv.waitKey无响应的原因及解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python实现网站的模拟登录
Jan 04 Python
探究python中open函数的使用
Mar 01 Python
Python线性回归实战分析
Feb 01 Python
Python元组及文件核心对象类型详解
Feb 11 Python
python删除文本中行数标签的方法
May 31 Python
pandas Dataframe行列读取的实例
Jun 08 Python
python numpy 部分排序 寻找最大的前几个数的方法
Jun 27 Python
python一键去抖音视频水印工具
Sep 14 Python
Python 获取windows桌面路径的5种方法小结
Jul 15 Python
python 使用socket传输图片视频等文件的实现方式
Aug 07 Python
selenium中get_cookies()和add_cookie()的用法详解
Jan 06 Python
Python Opencv中用compareHist函数进行直方图比较对比图片
Apr 07 Python
Python设计模式之迭代器模式原理与用法实例分析
Jan 10 #Python
Python设计模式之桥接模式原理与用法实例分析
Jan 10 #Python
Python基础教程之异常详解
Jan 10 #Python
Python+OpenCV感兴趣区域ROI提取方法
Jan 10 #Python
python+opencv 读取文件夹下的所有图像并批量保存ROI的方法
Jan 10 #Python
pandas ix &iloc &loc的区别
Jan 10 #Python
python 移动图片到另外一个文件夹的实例
Jan 10 #Python
You might like
2020显卡排行榜天梯图 显卡天梯图2020年3月最新版
2020/04/02 数码科技
php中检查文件或目录是否存在的代码小结
2012/10/22 PHP
用PHP编写和读取XML的几种方式
2013/01/12 PHP
PHP与JavaScript针对Cookie的读写、交互操作方法详解
2017/08/07 PHP
PHP的new static和new self的区别与使用
2019/11/27 PHP
根据地区不同显示时间的javascript代码
2007/08/13 Javascript
超级24小时弹窗代码 24小时退出弹窗代码 100%弹窗代码(IE only)
2010/06/11 Javascript
JavaScript的类型转换(字符转数字 数字转字符)
2010/08/30 Javascript
遍历jquery对象的代码分享
2011/11/02 Javascript
PHP开发者必须掌握的6个关键字
2014/04/14 Javascript
json字符串之间的相互转换示例代码
2014/08/21 Javascript
jQuery $命名冲突解决方案汇总
2014/11/13 Javascript
JS实现文件动态顺序载入的方法
2015/03/07 Javascript
js实现无缝滚动图
2017/02/22 Javascript
Bootstrap Table使用整理(三)
2017/06/09 Javascript
vue实现element-ui对话框可拖拽功能
2018/08/17 Javascript
JavaScript中Array方法你该知道的正确打开方法
2018/09/11 Javascript
你了解vue3.0响应式数据怎么实现吗
2019/06/07 Javascript
原生js实现针对Dom节点的CRUD操作示例
2019/08/26 Javascript
element-ui 实现响应式导航栏的示例代码
2020/05/08 Javascript
Python不使用int()函数把字符串转换为数字的方法
2018/07/09 Python
Django 表单模型选择框如何使用分组
2019/05/16 Python
python如何实现从视频中提取每秒图片
2020/10/22 Python
Python类的绑定方法和非绑定方法实例解析
2020/03/04 Python
如何使用scrapy中的ItemLoader提取数据
2020/09/30 Python
Veronica Beard官网:在酷、经典和别致之间找到了平衡
2018/01/11 全球购物
Boden英国官网:英国知名原创时装品牌
2018/11/06 全球购物
中专毕业生的自我鉴定
2013/12/01 职场文书
素质拓展感言
2014/01/29 职场文书
关于清明节的演讲稿
2014/09/13 职场文书
抗洪救灾标语
2014/10/08 职场文书
爱鸟护鸟的宣传语
2015/07/13 职场文书
浅谈Web Storage API的使用
2021/06/23 Javascript
html+css实现环绕倒影加载特效
2021/07/07 HTML / CSS
Win11 Dev 预览版25174.1000发布 (附更新修复内容汇总)
2022/08/05 数码科技
CSS使用SVG实现动态分布的圆环发散路径动画
2022/12/24 HTML / CSS