Release external data pointer in Cv::Mat constructor

asked 2014-06-24 23:41:38 -0600

huongnhat gravatar image

I have these following lines of code:

cv::Mat obj(size.cy, size.cx, CV_8UC3, dst_ptr/*, (size.cx * channels + 3) & -4*/);
source.copyTo(obj);
StretchDIBits( hdc, 0, 0, rect.right, rect.bottom, 0, 0, arr.cols, arr.rows, dst_ptr, binfo, DIB_RGB_COLORS, SRCCOPY );

These lines cause memory leak in my program. As document:

Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it

So how can I release the external data? Indeed it's the void *dst_ptr var

edit retag flag offensive close merge delete

Comments

Everytime I use delete dst_ptr the program crash

huongnhat gravatar imagehuongnhat ( 2014-06-24 23:46:25 -0600 )edit