C++ waitKey (30) 在 OpenCV 中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12452118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:17:03  来源:igfitidea点击:

what does waitKey (30) mean in OpenCV?

c++opencv

提问by Imbarfar

Possible Duplicate:
OpenCV - cvWaitKey( )

可能重复:
OpenCV - cvWaitKey()

I want to filter the video frame.

我想过滤视频帧。

for(;;)
{
cap.read( frame);
medianBlur(frame,framedst,5);
imshow("frame",frame);
imshow("framedst",framedst);    
if( waitKey (30) >= 0) break;
}

What does the waitKey(30)mean? Because if I comment out the line if( waitKey (30) >= 0) break;, the above code doesn't work!

这是什么waitKey(30)意思?因为如果我注释掉那行if( waitKey (30) >= 0) break;,上面的代码就行不通了!

采纳答案by tito

The function waitKey()waits for a key event for a "delay" (here, 30 milliseconds). As explained in the OpenCV documentation, HighGui (imshow()is a function of HighGui) need a call of waitKey regularly, in order to process its event loop.

该函数waitKey()等待按键事件的“延迟”(此处为 30 毫秒)。正如OpenCV 文档中所解释的,HighGui(imshow()是HighGui的一个函数)需要定期调用 waitKey,以处理其事件循环。

Ie, if you don't call waitKey, HighGui cannot process windows events like redraw, resizing, input event, etc. So just call it, even with a 1ms delay :)

即,如果您不调用 waitKey,HighGui 无法处理窗口事件,如重绘、调整大小、输入事件等。所以只需调用它,即使延迟 1 毫秒 :)