Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

End of Video File OpenCV

Tags:

opencv

Does anyone know how to check for the EOF(End of File) condition in OpenCV/C++ ? For example to check for empty file condition we can use the isEmpty() method, which returns a Boolean value. Is there any such method for catching EOF exceptions ?

Cheers.

like image 754
Roy2511 Avatar asked Jan 20 '14 13:01

Roy2511


People also ask

What does cv2 VideoCapture do?

cv2. VideoCapture – Creates a video capture object, which would help stream or display the video.

What is RET in Opencv?

Basically, ret is a boolean regarding whether or not there was a return at all, at the frame is each frame that is returned. If there is no frame, you wont get an error, you will get None. gray = cv2. cvtColor(frame, cv2. COLOR_BGR2GRAY)


1 Answers

There is also a similar function called empty() for you to use. Check out:

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;
    }
}
like image 55
herohuyongtao Avatar answered Oct 25 '22 06:10

herohuyongtao