Memory leak while using Mat

asked 2015-07-10 00:15:12 -0500

Hi all,

I'm new to OpenCV and I'm using OpenCV 2.49 libraries in my application. The objective of my application is to run in background, take pictures using web cam and save it as a BMP image in HDD. I've implemented it with openCV as follows,

VideoCapture camera(nCamera);

Mat frame;
bool bSuccess = camera.read(frame);
camera.set(CV_CAP_PROP_FRAME_WIDTH, m_nX);
camera.set(CV_CAP_PROP_FRAME_HEIGHT, m_nY);
bSuccess = camera.read(frame);

IplImage *img = new IplImage(frame);

//Convert to HBITMAP and write timestamp on the image
HBITMAP hbitmap = IplImage2DIB(img);

// Draw the timestamp 

//Save the image as BMP
delete img;

I have following queries,

  1. The memory profile of my application increases at every picture taken. With the initial analysis shows that the memory leaks at openCV structure. Kindly help me resolve this.

  2. Always the picture captured comes darker, if i take consecutive pictures only first picture is darker and the other comes normal. Why it is like this. Is there any setting i need to configure to correct it?

  3. Are there any built in functions available in openCV to draw/write on the image taken?

  4. Is it possible to save the frame as JPEG or BMP using OpenCV?

With the hope that some expert in openCV wil help me.

Thanks, RMK

edit retag flag offensive close merge delete

Comments

1

I don't know opencv 2.4.9 (i'm not an expert only I have read the documentation only) but after a quick reading of doc 2.4.11 may be you can use

  1. imwrite to save your image
  2. imshow to show your image
  3. use drawing fucntion

About memory leaks I haven't got any idea

LBerger gravatar imageLBerger ( 2015-07-10 02:13:24 -0500 )edit

Your biggest problem is 2.4.9. We have moved on and so should you, because 2.4.11 because tons of extra fixes. As long as your problem of memory leaks does not happen there, people will not try to fix old versions of the library. Also using IplImage *img = new IplImage(frame); is just horrible in the 2.4.9 interface. Please use the corresponding C++ functions.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-10 03:58:28 -0500 )edit