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.
cv2. VideoCapture – Creates a video capture object, which would help stream or display the video.
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)
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With