我的class1里面有两个函数,junhenghua( IplImage* src, IplImage* dst)用GetImageData(IplImage* src),这个GetImageData返回的是int**的。现在就是我在另外一个类中调用junhenghua( IplImage* src, IplImage* dst)这个算法,没用一次内存增加。请问如何释放GetImageData(IplImage* src)这个函数分配的内存,因为他就是返回值,也不能delete,求解答。
//读取像素点保存在数组中
IplImage* TrashTest:: junhenghua( IplImage* src, IplImage* dst)
{
int** whiteData;
int** trashData;
int** newpic;
int i,j;
whiteData=GetImageData(src);
trashData=GetImageData(dst);
newpic = new int *[src->height];
for (i=0; i<src->height; i++)
{
newpic[i] = new int[src->width];
}
for (i=0; i<src->height; i++)
{
for (j=0; j<src->width; j++)
{
newpic[i][j] = 100*trashData[i][j]/whiteData[i][j];
}
}
IplImage *copy = cvCreateImage(cvGetSize(dst), 8, 1);
for (i=0; i<src->height; i++)
{
for (j=0; j<src->width; j++)
{
cvSetReal2D(copy, i, j, newpic[i][j]);
}
}
return copy;
}
int** TrashTest::GetImageData(IplImage* srcImage)
{
int m = srcImage->height;
int n = srcImage->width;
int i, j;
// 分配内存
int **w;
w = new int *[m];
for (i=0; i<m; i++)
{
w[i] = new int[n];
}
// 将imgWROI->二位数组中
CvScalar s;
for (i=0; i<m; i++)
{
for (j=0; j<n; j++)
{
s = cvGet2D(srcImage, i, j);
w[i][j] = s.val[0];
}
}
return w;
}