2014-01-20 189 views
3

有谁知道如何检查OpenCV/C++中的EOF(文件结束)条件?例如,要检查空文件情况,我们可以使用isEmpty()方法,它返回一个布尔值。有没有这种方法来捕捉EOF异常?视频文件结束OpenCV

干杯。

回答

7

还有一个类似的功能叫empty()供您使用。退房时间:

VideoCapture cap("your_video.avi"); 
if(!cap.isOpened()) // check if we succeeded 
    return -1; 

Mat frame; 
while(1) // looply reading frames from the video file 
{ 
    cap >> frame; // try to get an image frame 

    if (frame.empty()) 
    { 
     // reach to the end of the video file 
     break; 
    } 
} 
+0

这是一个很好的方法。我会检查出来,谢谢! – Roy2511

+0

不工作的人。不能将“cap >> frame”转换为布尔值。 – Roy2511

+0

@ user3089908固定。 – herohuyongtao