Ask Your Question

Camera is not getting release?

asked 2013-12-21 21:46:03 -0500

shizzlej gravatar image

updated 2013-12-22 13:10:33 -0500

Hi support,

I can't seem to find the answer for this one. Someone had asked it before but he wasn't given a solution and I'm not sure if one was found (this was a year ago or so from the date of it). Here's a snippet of the code I'm running and the only part of it I'm concerned with:

videoStream = new cv::VideoCapture(2);

if ( !videoStream->isOpened() )
    addDebug("Capture failed!");
    delete videoStream;

*videoStream >> incFrame;

if ( !incFrame.empty() )

delete videoStream;

The problem is that this code will work the first time but never again during the lifetime of my program. If I close it and open the software again it works fine. I notice that after the camera is supposed to be released, it still looks like it is in use from looking at its LED. Is there something else I'm missing in regards to releasing the camera? I'm on OpenCV 2.4.5. I'm compiling on Ubuntu 12.04.

------------------ EDIT --------------------

Here are the messages I get everytime I try to execute the code when the software is in this state:

HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV

VIDIOC_STREAMON: Bad file descriptor

Unable to stop the stream.: Bad file descriptor

------------------ EDIT 2 ------------------

Okay I ran this same code on a laptop with a built-in webcam and it worked fine. The camera would turn off as I would expect. I guess it's just something either with the PC I was using or the camera I was using.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-12-21 22:48:44 -0500

stereomatching gravatar image

updated 2013-12-21 22:50:42 -0500

I don't know why do you want to new it?Just declare an automatic object, the resource will be clean up after the videoStream after it leave the scope.If this solution can't work, that means the problem may not on the videoCapture but other codes.

cv::VideoCapture videoStream(2);

if ( !videoStream.isOpened() )
    addDebug("Capture failed!");   

videoStream >> incFrame;

//you don't need these too, just declare an automatic object like
//cv::Mat incFrame.The resource will be clean up after leaving the scope
/*if ( !incFrame.empty() )

ps : If you find out you need to handle the memory manually in c++, maybe you should ask yourself "am I doing something wrong?".In c++, we could deal with memory management and pointer, but we don't "have to" do that.

edit flag offensive delete link more


Thanks! That seemed to fixed it. Can you explain why it was so broken the way I was originally trying to do it with the pointer? (doing new then delete) I'm fairly new to C++. Don't have to but something I'd like to understand better if possible

---------------- EDIT -------------------

Scratch that still the same thing happens. I forgot to reset the index used in videoStream(). Thanks for the input though!

shizzlej gravatar imageshizzlej ( 2013-12-21 23:09:15 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-12-21 21:46:03 -0500

Seen: 3,269 times

Last updated: Dec 22 '13