Ask Your Question

Revision history [back]

Memory leak while using Mat

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