OpenCV VideoCapture IP camera reconnection

柔情痞子 提交于 2019-12-12 11:06:15

问题


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

Mat src;
VideoCapture cap();
cap.open("http://192.168.1.10:8008"); // IP camera

while(1) {
    cap.read(src);
    // 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.


回答1:


http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-read

If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

try this

if(cap.read(src) == false ) break;



来源:https://stackoverflow.com/questions/17697923/opencv-videocapture-ip-camera-reconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!