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();