关于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中操作字典之update()方法的使用
May 22 Python
Python嵌套列表转一维的方法(压平嵌套列表)
Jul 03 Python
Django 实现购物车功能的示例代码
Oct 08 Python
浅谈Scrapy网络爬虫框架的工作原理和数据采集
Feb 07 Python
用python写一个定时提醒程序的实现代码
Jul 22 Python
Python使用APScheduler实现定时任务过程解析
Sep 11 Python
Tensorflow中tf.ConfigProto()的用法详解
Feb 06 Python
python模式 工厂模式原理及实例详解
Feb 11 Python
pip安装tensorflow的坑的解决
Apr 19 Python
django中嵌套的try-except实例
May 21 Python
详解PyQt5中textBrowser显示print语句输出的简单方法
Aug 07 Python
python 爬虫之selenium可视化爬虫的实现
Dec 04 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
关于使用key/value数据库redis和TTSERVER的心得体会
2013/06/28 PHP
php+ajax制作无刷新留言板
2015/10/27 PHP
js获取当前select 元素值的代码
2010/04/19 Javascript
javascript实现动态改变层大小的方法
2015/05/14 Javascript
第六章之辅组类与响应式工具
2016/04/25 Javascript
JS获取鼠标选中的文字
2016/08/10 Javascript
jQuery实现自动输入email、时间和域名的方法
2016/08/24 Javascript
JS实现重新加载当前页面
2016/11/29 Javascript
Bootstrap中data-target 到底是什么
2017/02/14 Javascript
nodejs集成sqlite使用示例
2017/06/05 NodeJs
简单介绍react redux的中间件的使用
2018/04/06 Javascript
vue将单页面改造成多页面应用的方法
2018/11/25 Javascript
vue实现数据控制视图的原理解析
2020/01/07 Javascript
微信小程序分享小程序码的生成(带参数)以及参数的获取
2020/03/25 Javascript
如何实现js拖拽效果及原理解析
2020/05/08 Javascript
微信小程序点击滚动到指定位置的实现
2020/05/22 Javascript
javascript实现智能手环时间显示
2020/09/18 Javascript
[03:10]超级美酒第四天 fy拉比克秀 大合集
2018/06/05 DOTA
python开发之str.format()用法实例分析
2016/02/22 Python
Scrapy使用的基本流程与实例讲解
2018/10/21 Python
基于python的ini配置文件操作工具类
2019/04/24 Python
Python实现播放和录制声音的功能
2020/08/12 Python
Python与C/C++的相互调用案例
2021/03/04 Python
css3实现元素环绕中心点布局的方法示例
2019/01/15 HTML / CSS
HTML文本属性&颜色控制属性的实现
2019/12/17 HTML / CSS
Too Faced官网:美国知名彩妆品牌
2017/03/07 全球购物
社区庆八一活动方案
2014/02/02 职场文书
入学申请自荐信范文
2014/02/26 职场文书
村委会换届选举方案
2014/05/03 职场文书
建议书的格式
2014/05/12 职场文书
领导干部遵守党的政治纪律情况思想汇报
2014/09/14 职场文书
2014年保洁员工作总结
2014/11/19 职场文书
2014年学生工作总结
2014/11/20 职场文书
2015年音乐教学工作总结
2015/07/22 职场文书
创业计划书之韩国烧烤店
2019/09/19 职场文书
Python获取江苏疫情实时数据及爬虫分析
2021/08/02 Python