关于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标准算法实现数组全排列的方法
Mar 17 Python
将Python的Django框架与认证系统整合的方法
Jul 24 Python
python 按不同维度求和,最值,均值的实例
Jun 28 Python
Django管理员账号和密码忘记的完美解决方法
Dec 06 Python
在python里面运用多继承方法详解
Jul 01 Python
python3反转字符串的3种方法(小结)
Nov 07 Python
Python二次规划和线性规划使用实例
Dec 09 Python
Python谱减法语音降噪实例
Dec 18 Python
Tensorflow 多线程设置方式
Feb 06 Python
tensorflow保持每次训练结果一致的简单实现
Feb 17 Python
python实现简单的五子棋游戏
Sep 01 Python
Django项目配置Memcached和Redis, 缓存选择哪个更有优势
Apr 06 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
一个简单的域名注册情况查询程序
2006/10/09 PHP
php 上一篇,下一篇文章实现代码与原理说明
2010/05/09 PHP
smarty中post用法实例
2014/11/28 PHP
Symfony2联合查询实现方法
2016/03/18 PHP
PHP内存缓存功能memcached示例
2016/10/19 PHP
解决PHP上传非标准格式的图片pjpeg失败的方法
2017/03/12 PHP
PHP获取ttf格式文件字体名的方法示例
2019/03/06 PHP
通用于ie和firefox的函数 GetCurrentStyle (obj, prop)
2006/12/27 Javascript
jquery 防止表单重复提交代码
2010/01/21 Javascript
JavaScript和JQuery实用代码片段(一)
2010/04/07 Javascript
JS获取浏览器版本及名称实现函数
2013/04/02 Javascript
jQuery避免$符和其他JS库冲突的方法对比
2014/02/20 Javascript
基于jQuery实现点击最后一行实现行自增效果的表格
2016/01/12 Javascript
结合代码图文讲解JavaScript中的作用域与作用域链
2016/07/05 Javascript
微信小程序 教程之模块化
2016/10/17 Javascript
BootstrapTable请求数据时设置超时(timeout)的方法
2017/01/22 Javascript
vue2实现移动端上传、预览、压缩图片解决拍照旋转问题
2017/04/13 Javascript
bootstrap Table服务端处理分页(后台是.net)
2017/10/19 Javascript
node vue项目开发之前后端分离实战记录
2017/12/13 Javascript
Vue2.0中集成UEditor富文本编辑器的方法
2018/03/03 Javascript
nuxt.js 在middleware(中间件)中实现路由鉴权操作
2020/11/06 Javascript
Python中的二叉树查找算法模块使用指南
2014/07/04 Python
使用Python读写文本文件及编写简单的文本编辑器
2016/03/11 Python
python绘制双柱形图代码实例
2017/12/14 Python
对python中的高效迭代器函数详解
2018/10/18 Python
Python实现迪杰斯特拉算法过程解析
2020/09/18 Python
python 输入字符串生成所有有效的IP地址(LeetCode 93号题)
2020/10/15 Python
波兰家居和花园家具专家:4Home
2019/05/26 全球购物
品质主管的岗位职责
2013/12/04 职场文书
小学安全汇报材料
2014/08/14 职场文书
黄山导游词
2015/01/31 职场文书
学生逃课万能检讨书2000字
2015/02/17 职场文书
导师工作推荐信
2015/03/27 职场文书
外贸采购员岗位职责
2015/04/03 职场文书
深入理解python多线程编程
2021/04/18 Python
vue选项卡切换的实现案例
2022/04/11 Vue.js