Ask Your Question
0

Check for camera disconnection / down

asked 2013-11-12 00:51:28 -0500

swejnc gravatar image

updated 2013-11-12 05:00:23 -0500

berak gravatar image

I was capturing video from camera, I need to know if the camera is disconnected or down, is there a way to check?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-11-12 04:39:52 -0500

updated 2013-11-12 04:42:34 -0500

Try to read frame, if you can't it probably means that the camera was disconnected.

VideoCapture cap;
Mat frame;

cap.open(0);

    if(!cap.read(frame))
        {
            cout << "failed to read frame";
            return;
        }

There's also a cap.IsOpened() method that returns 1 or 0, if the VideoCapture object is opened or not.

edit flag offensive delete link more

Comments

I need to check for more than one time, let say every loop of capturing, I need to know when the camera is down. Once the camera works, IsOpened() always return true even the camera goes down after that. If I use cap.open(0) in a loop, it cause memory leak.

swejnc gravatar imageswejnc ( 2013-11-12 18:47:06 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-11-12 00:51:28 -0500

Seen: 925 times

Last updated: Nov 12 '13