Ask Your Question

Check camera activity

asked 2019-11-12 07:02:19 -0500

prawn gravatar image


How can I check a camera activity?

I would like to know is camera on/off AND is any program currently use a camera? I tested the code from

int main(int, char**)
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;
    Mat edges;
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, COLOR_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if(waitKey(30) >= 0) break;
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;

I opened Skype -> Setting -> Camera Preview. Camera switched on. Then I executed the code. Only in "for" section after line "cap>>frame;" I understood than another program has already captured the camera.

I found out that by check:

if (frame.rows == 0 && frame.cols == 0 && == 0)

If I close Skype and call from the code

cap>>frame;        or           cap.grab();             or   ;

I turn camera on. (I see light on my device). Is it possible to check camera activity without starting "record video" ?

I tried to compare different properties when camera on and off.

double prop1= cap.get(CAP_PROP_POS_MSEC);
double prop2= cap.get(CAP_PROP_POS_FRAMES);
double prop18= cap.get(CAP_PROP_WHITE_BALANCE_BLUE_U);
double prop19= cap.get(CAP_PROP_RECTIFICATION);

But the results are the same.

Is exists approach to check camera activity without "switch camera on" for a second?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-11-12 07:07:31 -0500

berak gravatar image

Is exists approach to check camera activity without "switch camera on" ?

NO. (at least not from opencv)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-11-12 07:02:19 -0500

Seen: 42 times

Last updated: Nov 12