Ask Your Question

paty.r15's profile - activity

2020-06-22 07:09:40 -0600 received badge  Notable Question (source)
2019-03-25 19:50:41 -0600 received badge  Popular Question (source)
2016-05-20 09:59:17 -0600 received badge  Student (source)
2016-04-21 15:23:58 -0600 asked a question 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?