关于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之玩转字符串(2)更新篇
Sep 28 Python
python根据给定文件返回文件名和扩展名的方法
Mar 27 Python
基于hashlib模块--加密(详解)
Jun 21 Python
Python 模拟购物车的实例讲解
Sep 11 Python
python numpy函数中的linspace创建等差数列详解
Oct 13 Python
Python编程中flask的简介与简单使用
Dec 28 Python
Python实现定制自动化业务流量报表周报功能【XlsxWriter模块】
Mar 11 Python
Python求均值,方差,标准差的实例
Jun 29 Python
Python Web框架之Django框架cookie和session用法分析
Aug 16 Python
python求绝对值的三种方法小结
Dec 04 Python
Python3直接爬取图片URL并保存示例
Dec 18 Python
python中os.remove()用法及注意事项
Jan 31 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实现文件上传二法
2006/10/09 PHP
PHP实现网上点歌(二)
2006/10/09 PHP
PHP中删除变量时unset()和null的区别分析
2011/01/27 PHP
php 无法加载mcrypt.dll的解决办法
2013/04/03 PHP
php htmlspecialchars()与shtmlspecialchars()函数的深入分析
2013/06/05 PHP
PHP有序表查找之二分查找(折半查找)算法示例
2018/02/09 PHP
YII2框架中ActiveDataProvider与GridView的配合使用操作示例
2020/03/18 PHP
jquery submit ie6下失效的原因分析及解决方法
2013/11/15 Javascript
Javascript字符串对象的常用方法简明版
2014/06/26 Javascript
JavaScript利用正则表达式去除日期中的“-”
2014/07/01 Javascript
AngularJS Module方法详解
2015/12/08 Javascript
JavaScript程序设计之JS调试
2015/12/09 Javascript
Ionic3 UI组件之autocomplete详解
2017/06/08 Javascript
Vue兼容ie9的问题全面解决方案
2018/06/19 Javascript
浅谈在vue中使用mint-ui swipe遇到的问题
2018/09/27 Javascript
微信小程序录音实现功能并上传(使用node解析接收)
2020/02/26 Javascript
vscode+gulp轻松开发小程序的完整步骤
2020/10/18 Javascript
[43:51]2018DOTA2亚洲邀请赛3月30日 小组赛B组 EG VS Secret
2018/03/31 DOTA
python删除列表中重复记录的方法
2015/04/28 Python
python提取页面内url列表的方法
2015/05/25 Python
Python中的数据对象持久化存储模块pickle的使用示例
2016/03/03 Python
Python实现计算两个时间之间相差天数的方法
2017/05/10 Python
Keras中的多分类损失函数用法categorical_crossentropy
2020/06/11 Python
python绘制分布折线图的示例
2020/09/24 Python
CSS3弹性布局内容对齐(justify-content)属性使用详解
2017/07/31 HTML / CSS
给定一个时间点,希望得到其他时间点
2013/11/07 面试题
体育教学随笔感言
2014/02/24 职场文书
庆六一活动总结
2014/08/29 职场文书
学生抄袭作业的检讨书
2014/10/02 职场文书
2014年教师学期工作总结
2014/11/08 职场文书
工作检讨书怎么写
2015/01/23 职场文书
2016年幼儿园教研活动总结
2016/04/05 职场文书
教你怎么用Python实现GIF动图的提取及合成
2021/06/15 Python
javascript实现计算器功能详解流程
2021/11/01 Javascript
拙作再改《我的收音机情缘》
2022/04/05 无线电
JS前端轻量fabric.js系列物体基类
2022/08/05 Javascript