关于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 k-近邻算法实例分享
Jun 11 Python
Python深入学习之对象的属性
Aug 31 Python
快速查询Python文档方法分享
Dec 27 Python
python 去除txt文本中的空格、数字、特定字母等方法
Jul 24 Python
vscode 配置 python3开发环境的方法
Sep 19 Python
OpenCV模板匹配matchTemplate的实现
Oct 18 Python
Python log模块logging记录打印用法解析
Jan 20 Python
Python如何把多个PDF文件合并代码实例
Feb 13 Python
python学习笔记之多进程
Aug 06 Python
Python基于gevent实现文件字符串查找器
Aug 11 Python
Python实现Telnet自动连接检测密码的示例
Apr 16 Python
Python源码解析之List
May 21 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之apc
2013/05/15 PHP
php实现12306火车票余票查询和价格查询(12306火车票查询)
2014/01/14 PHP
PHP中iconv函数知识汇总
2015/07/02 PHP
是 WordPress 让 PHP 更流行了 而不是框架
2016/02/03 PHP
PHP后期静态绑定之self::限制实例分析
2018/12/21 PHP
Smarty模板语法详解
2019/07/20 PHP
JavaScript中使用构造器创建对象无需new的情况说明
2012/03/01 Javascript
jquery 实现二级/三级/多级联动菜单的思路及代码
2013/04/08 Javascript
js子页面获取父页面数据示例
2014/05/15 Javascript
JS动态修改表格cellPadding和cellSpacing的方法
2015/03/31 Javascript
通过实例理解javascript中没有函数重载的概念
2015/06/03 Javascript
基于BootStrap的Metronic框架实现页面链接收藏夹功能按钮移动收藏记录(使用Sortable进行拖动排序)
2016/08/29 Javascript
jQuery插件FusionCharts实现的MSBar3D图效果示例【附demo源码】
2017/03/23 jQuery
jQuery自定义图片上传插件实例代码
2017/04/04 jQuery
js中json对象和字符串的理解及相互转化操作实现方法
2017/09/22 Javascript
详解Webpack多环境代码打包的方法
2018/08/03 Javascript
jQuery实现每日秒杀商品倒计时功能
2019/09/06 jQuery
关于layui 实现点击按钮添加一行(方法渲染创建的table)
2019/09/29 Javascript
vue 监听窗口变化对页面部分元素重新渲染操作
2020/07/28 Javascript
[48:46]完美世界DOTA2联赛PWL S2 SZ vs FTD.C 第二场 11.19
2020/11/19 DOTA
Python实现数通设备端口使用情况监控实例
2015/07/15 Python
Python中防止sql注入的方法详解
2017/02/25 Python
一行代码让 Python 的运行速度提高100倍
2018/10/08 Python
python实现while循环打印星星的四种形状
2019/11/23 Python
Python实现随机取一个矩阵数组的某几行
2019/11/26 Python
Python3.7黑帽编程之病毒篇(基础篇)
2020/02/04 Python
python默认参数调用方法解析
2020/02/09 Python
将python文件打包exe独立运行程序方法详解
2020/02/12 Python
Python 如何实现数据库表结构同步
2020/09/29 Python
html5+CSS3+JS实现七夕言情功能代码
2017/08/28 HTML / CSS
小学教师先进事迹材料
2014/12/15 职场文书
汽车质检员岗位职责
2015/04/08 职场文书
如何写辞职信
2015/05/13 职场文书
CSS3 实现NES游戏机的示例代码
2021/04/21 HTML / CSS
2022漫威和DC电影上映作品
2022/04/05 欧美动漫
Redis唯一ID生成器的实现
2022/07/07 Redis