OpenCV的imshow无法正常显示视频

OpenCV2.2,vs2010,win7

程序读一段视频,然后进行分析处理,在显示视频的时候,却发现imshow无法显示读取的帧。代码如下:

VideoCapture cap;
cap.open("test.avi");
namedWindow("video",1);
for(;;){
Mat frame;
cap< if(frame.empty())
break;
imshow("video",frame);
//waitKey(30)
}


跟踪了一下,发现确实是读入了帧,只是在显示的时候没有出来。
在网上查了下文档,原来是循环中,highgui没有给予imshow绘制处理的时间。需要在imshow添加waitKey(30)
[quote]A common mistake for opencv newcomers is to call cv::imshow() in a loop through video frames, without following up each draw with cv::waitKey(30). In this case, nothing appears on screen, because highgui is never given time to process the draw requests from cv::imshow().
[/quote]
来自:[url]http://stackoverflow.com/questions/5217519/opencv-cvwaitkey[/url]

你可能感兴趣的:(opencv,OpenCV,机器视觉)