视频文件结束OpenCV

时间:2014-01-20 13:55:00

标签: opencv

有没有人知道如何检查OpenCV / C ++中的EOF(文件结束)条件?例如,为了检查空文件条件,我们可以使用isEmpty()方法,该方法返回一个布尔值。是否有任何此类方法可以捕获EOF异常?

干杯。

1 个答案:

答案 0 :(得分:8)

还有一个名为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;
    }
}