OpenCv中,waitkey()函数失效原因

OepnCv库中,waitkey函数失效原因

  • 情景描述
  • 原因
  • HighGUI 函数

情景描述

在写一个自动化脚本,然后再某一个循环里,使用了如下代码:

while True:
    # ord 函数, 根据键盘的输入返回一个ASCII码值 ,有时候 waitkey返回的值会大于255,进行按位与,避免一些奇奇怪怪的bug
    if ord('q') == cv2.waitKey(0) & 0xFF:
        break
    print(1) # something working code.

原因

但是,运行后,一直无法通过监测按键q来使得脚本停止作用。在opencv的函数说明手册里,有这么一句话。

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.

即该函数必须作用在至少有一个 highGUI 窗口上,但是我的代码是没有的,所以一直不能起作用。

HighGUI 函数

imgread,imgshow等等。。

你可能感兴趣的:(opencv,计算机视觉,python)