Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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);
    Mat frame;
        // do stuff