Ask Your Question

giroy's profile - activity

2012-12-10 18:36:01 -0600 received badge  Student (source)
2012-09-19 11:44:15 -0600 asked a question Detecting unplugged camera with OpenCV2.4

I just upgraded to OpenCV2.4 and I'm trying to detect when a camera is unplugged. According to the documentation on the cv::VideoCapture::read command, "if no frames have 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." However, in my application, this is not the case. When I unplug the camera, it keeps reading the last frame from when the camera was plugged in and never returns false or NULL. Is this a bug in OpenCV or am I doing something wrong? My code is below.

VideoCapture cap(0);
if(cap.isOpened()){
    Mat frame;
    while(cap.read(frame)){
        // do stuff
        Sleep(30);
    }
}
cap.release();