cv2.waitkey() code snippet explanation

python 复制代码
if cv2.waitKey(0) & 0xFF == ord('q'):
        break

通常,我们看到上述句子,用于在指定的时间内等待击键,通常用于图像和视频处理应用程序中,以暂停执行并允许用户与显示的窗口交互。

python 复制代码
cv2.waitkey(0)    # wait indefinitely
cv2.waitkey(3000)    # wait for 3000ms, which is 3s

至于 ord(),它用于返回字符的 unicode编码。

In Python, the ord() function returns the Unicode code for a character. This function takes a unit-length text as an argument and returns the Unicode equivalent of the specified parameter. The ord() function is used to convert a single character into its integer Unicode code value. The function only accepts a string with the length of onehttps://www.bing.com/ck/a?!&&p=875d7487e2e8b060a85beef00f83920bbebc2a908f282873dff588db0080cd2fJmltdHM9MTc0MjUxNTIwMA&ptn=3&ver=2&hsh=4&fclid=266c1486-d8f0-602c-0b69-010cd9966195&psq=ord+python&u=a1aHR0cHM6Ly9sZWFybnB5dGhvbi5jb20vYmxvZy9vcmQtZnVuY3Rpb24taW4tcHl0aG9uLw&ntb=1此处 & 的目的是为了提取出 后8位。cv2.waitKey() 返回一个 32-bit 的整数,通过按位与操作,提取出后八位,并将结果 与 'q' 的 Unicode码进行比较。(Unicode 码 是 ASCII 码的超集)

所以,上述代码会一直等待,直到你 输入'q'。

link:

https://stackoverflow.com/questions/35372700/whats-0xff-for-in-cv2-waitkey1

相关推荐
MARS_AI_3 小时前
云蝠智能 Voice Agent 落地展会邀约场景:重构会展行业的智能交互范式
人工智能·自然语言处理·重构·交互·语音识别·信息与通信
weixin_422456444 小时前
第N7周:调用Gensim库训练Word2Vec模型
人工智能·机器学习·word2vec
HuggingFace7 小时前
Hugging Face 开源机器人 Reachy Mini 开启预定
人工智能
企企通采购云平台8 小时前
「天元宠物」×企企通,加速数智化升级,“链”接萌宠消费新蓝海
大数据·人工智能·宠物
超级小忍8 小时前
Spring AI ETL Pipeline使用指南
人工智能·spring
张较瘦_8 小时前
[论文阅读] 人工智能 | 读懂Meta-Fair:让LLM摆脱偏见的自动化测试新方法
论文阅读·人工智能
一只小灿灿9 小时前
前端计算机视觉:使用 OpenCV.js 在浏览器中实现图像处理
前端·opencv·计算机视觉
巴伦是只猫9 小时前
【机器学习笔记 Ⅲ】4 特征选择
人工智能·笔记·机器学习
好心的小明9 小时前
【王树森推荐系统】召回11:地理位置召回、作者召回、缓存召回
人工智能·缓存·推荐系统·推荐算法
lishaoan779 小时前
使用tensorflow的线性回归的例子(十二)
人工智能·tensorflow·线性回归·戴明回归