OpenCV的imshow没法正常显示视频
OpenCV的imshow无法正常显示视频OpenCV2.2,vs2010,win7程序读一段视频,然后进行分析处理,在显示视频的时候
OpenCV的imshow无法正常显示视频
OpenCV2.2,vs2010,win7
程序读一段视频,然后进行分析处理,在显示视频的时候,却发现imshow无法显示读取的帧。代码如下:
VideoCapture cap;cap.open("test.avi");namedWindow("video",1);for(;;){ Mat frame; cap<<frame; if(frame.empty())break; imshow("video",frame); //waitKey(30)}
跟踪了一下,发现确实是读入了帧,只是在显示的时候没有出来。
在网上查了下文档,原来是循环中,highgui没有给予imshow绘制处理的时间。需要在imshow添加waitKey(30)
引用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().
来自:http://stackoverflow.com/questions/5217519/opencv-cvwaitkey 1 楼 haibuo1981 2012-02-10 先前的描述有问题,已修正