【发布时间】:2016-09-26 17:09:57
【问题描述】:
我正在使用 OpenCV,我希望 OpenCV 不等待 any 键被按下(默认行为为cv2.waitKey()),而是等待特定的键我定义(并执行后续操作)。
我目前对这个问题的解决方案是以下递归解决方案:
def opencv_wait():
# wait for keypress; capture it
k = cv2.waitKey(0)
if k == 27: # this should be ESC
return # e.g. end the program
elif k == some_key: # some other keys...
do_some_function() # ...and actions to do after key is pressed
else:
opencv_wait() # recursively call opencv_wait() for looping
我的问题是:这个解决方案是让 OpenCV 等待不同键的便捷方式吗?
有没有更快/更好的方法来实现我想做的事情?
基本上,我希望 OpenCV 无限长地等待(尽可能少地浪费资源),直到按下应该触发后续操作的特定键。
【问题讨论】:
-
我也在找这个。不幸的是,我认为没有更好的方法来等待特定的密钥。
标签: python python-2.7 opencv wait keypress