IP camera disconnection and reconnection issues

asked 2013-07-18 04:33:34 -0500

dablak gravatar image

updated 2013-07-18 04:43:11 -0500

I'm reading images from a camera through HTTP. This is the code:

Mat src;
VideoCapture cap();
cap.open(""); // IP camera

while(1) {
    // Other code

It works perfectly, but after running for a while if I physically disconnect the camera then the code hangs forever in cap.read(src);.

I need some way to return from read if, let's say, after 5 seconds there is no new image.

There is another problem. If the camera is reconnected while the program is waiting in read then it keeps hanged anyway. It would be good if VideoCapture is able to grab frames again once the camera is reconnected.

edit retag flag offensive close merge delete