在OpenCV中,waitKey(30)是什么意思? [重复]

可能重复:   OpenCV-cvWaitKey()

我想过滤视频帧。

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!

最佳答案

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,HighGui将无法处理Windows事件,例如重绘,调整大小,输入事件等。因此,即使有1ms的延迟,也只需调用它即可:)