Ask Your Question
0

Check camera activity

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

prawn gravatar image

Hello

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 https://docs.opencv.org/3.0.0/d8/dfe/...

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;
    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        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 && frame.data == 0)

If I close Skype and call from the code

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

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
1

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

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

Question Tools

1 follower

Stats

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

Seen: 263 times

Last updated: Nov 12 '19