Camera is not getting release?

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:

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:

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.

1 answer

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.

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.

Comments

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!