关于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中pygame模块用法实例
Oct 09 Python
利用python操作SQLite数据库及文件操作详解
Sep 22 Python
Python内置模块ConfigParser实现配置读写功能的方法
Feb 12 Python
详解Python3中ceil()函数用法
Feb 19 Python
Python使用reportlab模块生成PDF格式的文档
Mar 11 Python
pyqt5 实现工具栏文字图片同时显示
Jun 13 Python
Python爬取腾讯视频评论的思路详解
Dec 19 Python
python DataFrame转dict字典过程详解
Dec 26 Python
python异常处理try except过程解析
Feb 03 Python
tf.concat中axis的含义与使用详解
Feb 07 Python
jupyter notebook 多行输出实例
Apr 09 Python
不到20行实现Python代码即可制作精美证件照
Apr 24 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
php 获得汉字拼音首字母的函数
2009/08/01 PHP
基于PHP5魔术常量与魔术方法的详解
2013/06/13 PHP
利用laravel搭建一个迷你博客实战教程
2017/08/13 PHP
JQery jstree 大数据量问题解决方法
2010/03/09 Javascript
jquery动态添加删除div 具体实现
2013/07/20 Javascript
iframe子页面与父页面在同域或不同域下的js通信
2014/05/07 Javascript
js网页滚动条滚动事件实例分析
2015/05/05 Javascript
js获得当前系统日期时间的方法
2015/05/06 Javascript
浅谈Javascript实现继承的方法
2015/07/06 Javascript
jquery仿百度百科底部浮动导航特效
2015/08/08 Javascript
javascript实现保留两位小数的多种方法
2015/12/18 Javascript
AngularJS在IE下取数据总是缓存问题的解决方法
2016/08/05 Javascript
jQuery实现点击查看大图并以弹框的形式居中
2016/08/08 Javascript
最原始的jQuery注册验证方式
2016/10/11 Javascript
String字符串截取的四种方式总结
2016/11/28 Javascript
基于Bootstrap的标签页组件及bootstrap-tab使用说明
2017/07/25 Javascript
通过jquery的ajax请求本地的json文件方法
2018/08/08 jQuery
JS加密插件CryptoJS实现AES加密操作示例
2018/08/16 Javascript
js Array.slice的8种不同用法示例
2019/07/10 Javascript
[01:10:58]Spirit vs NB Supermajor小组赛 A组败者组决赛 BO3 第二场 6.2
2018/06/03 DOTA
Python Trie树实现字典排序
2014/03/28 Python
python监控网卡流量并使用graphite绘图的示例
2014/04/27 Python
Python中xrange与yield的用法实例分析
2017/12/26 Python
如何利用Python写个坦克大战
2020/11/18 Python
python 如何在测试中使用 Mock
2021/03/01 Python
CSS图片翻转动画技术详解(IE也实现了)
2014/04/03 HTML / CSS
Java面试题汇总
2015/12/06 面试题
鞋类设计与工艺专业销售求职信
2013/11/01 职场文书
商场消防管理制度
2014/01/12 职场文书
创先争优承诺书范文
2014/03/31 职场文书
公司周年庆典策划方案
2014/05/17 职场文书
小学运动会口号
2014/06/07 职场文书
秋季校运会广播稿100字
2014/09/18 职场文书
数学教师个人总结
2015/02/06 职场文书
2015年市场部工作总结
2015/04/30 职场文书
教师专业技术工作总结2015
2015/05/13 职场文书