Ask Your Question

Revision history [back]

Basically what you need to do before reading an image from a cam element.

VideoCapture cap(0); // open the default camera
if(!cap.isOpened())  // check if we succeeded
    return -1;

This code will check if the cam opening actually worked. If the camera is busy, it will not get opened, since access isn't allowed, giving you a false for an opened camera socket.