关于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下载FTP上的文件夹的实现代码
Feb 10 Python
Python模仿POST提交HTTP数据及使用Cookie值的方法
Nov 10 Python
在Python中使用PIL模块处理图像的教程
Apr 29 Python
Python的自动化部署模块Fabric的安装及使用指南
Jan 19 Python
Python字符串拼接六种方法介绍
Dec 18 Python
对python requests发送json格式数据的实例详解
Dec 19 Python
详解Python连接MySQL数据库的多种方式
Apr 16 Python
Python实现链表反转的方法分析【迭代法与递归法】
Feb 22 Python
Python读取配置文件(config.ini)以及写入配置文件
Apr 08 Python
Selenium及python实现滚动操作多种方法
Jul 21 Python
Python页面加载的等待方式总结
Feb 28 Python
pytorch中Schedule与warmup_steps的用法说明
May 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 adodb分页实现代码
2009/03/19 PHP
推荐10个提供免费PHP脚本下载的网站
2014/12/31 PHP
基于php实现七牛抓取远程图片
2015/12/01 PHP
PHP实现微信模拟登陆并给用户发送消息的方法【文字,图片,图文】
2017/06/29 PHP
PHP中数组转换为SimpleXML教程
2019/01/27 PHP
真正的JQuery.ajax传递中文参数的解决方法
2011/05/28 Javascript
jQuery中将函数赋值给变量的调用方法
2012/03/23 Javascript
js判断变量是否未定义的代码
2020/03/28 Javascript
JQuery的Ajax中Post方法传递中文出现乱码的解决方法
2014/10/21 Javascript
jQuery中append()方法用法实例
2014/12/25 Javascript
AngularJS延迟加载html template
2016/07/27 Javascript
学习使用Bootstrap栅格系统
2017/05/11 Javascript
JS实现合并json对象的方法
2017/10/10 Javascript
jQuery实现表格隔行换色
2018/09/01 jQuery
Vuejs2 + Webpack框架里,模拟下载的实例讲解
2018/09/05 Javascript
原生JS实现的放大镜特效示例【测试可用】
2018/12/08 Javascript
原生js实现碰撞检测
2020/03/12 Javascript
element-ui中el-upload多文件一次性上传的实现
2020/12/02 Javascript
[45:25]完美世界DOTA2联赛循环赛 PXG vs IO 第一场 11.06
2020/11/09 DOTA
Linux上安装Python的PIL和Pillow库处理图片的实例教程
2016/06/23 Python
Linux RedHat下安装Python2.7开发环境
2017/05/20 Python
使用python获取csv文本的某行或某列数据的实例
2018/04/03 Python
用Python编写一个高效的端口扫描器的方法
2018/12/20 Python
对python以16进制打印字节数组的方法详解
2019/01/24 Python
pytorch 实现打印模型的参数值
2019/12/30 Python
使用python自动追踪你的快递(物流推送邮箱)
2020/03/17 Python
python 使用事件对象asyncio.Event来同步协程的操作
2020/05/04 Python
使用Python封装excel操作指南
2021/01/29 Python
HTML5通用接口详解
2016/06/12 HTML / CSS
七年级地理教学反思
2014/01/26 职场文书
租车协议书范本
2014/04/22 职场文书
小学生志愿者活动方案
2014/08/23 职场文书
英语课前三分钟演讲稿(6篇)
2014/09/13 职场文书
学校政风行风整改方案
2014/10/25 职场文书
幼儿园中班教师个人总结
2015/02/05 职场文书
「女孩的钓鱼慢活」全新版权绘公布
2022/03/21 日漫