Videocapture suddenly blocks on reading a frame from IP camera
I'm using OpenCV 3. Grabbing a frame using VideoCapture with an IP Camera is blocking if the camera goes disconnected from the network or there is an issue with a frame. I first check if videoCapture.isOpened(). If it is, I tried these methods but nothing seems to work:
1) grabber >> frame
if(grabber.isOpened()) {
grabber >> frame;
// DO SOMETHING WITH FRAME
}
2) read
if(grabber.isOpened()) {
if(!grabber.grab()){
cout << "failed to grab from camera" << endl;
} else {
if (grabber.retrieve(frame,0) ){
// DO SOMETHING WITH FRAME
} else {
// SHOW ERROR
}
}
}
3) grab/retrieve
if(grabber.isOpened()) {
if ( !grabber.read(frame) ) {
cout << "Unable to retrieve frame from video stream." << endl;
}
else {
// DO SOMETHING WITH FRAME
}
}
The video stream gets stuck at some point grabbing a frame with all of the previous options, each one blocks but doesn't exit or returns any error.
Do you know if there is a way to handle or solve this? Maybe some validations, try/catch or timer?
Did you make any progress on this? I've recently experienced the same thing. In my case, sporadically, VideoCapture::read() blocks when it experiences a particular type of error (I don't know exactly the nature of the error, but one of my cameras produces it). In this case the read() call never returns...