Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create an image array using IplImage.Here is my code for that.But it provides some memory leaks.Please help me with this to solve this problem.
C++
IplImage *result[200];  

for(int i=0;i<160;i++)
{
    result[i]=cvCreateImage(cvGetSize(Segimg), 8, 1);
}

*result=method();

cvNamedWindow("B:");
cvShowImage("B:", result[1]);
cvWaitKey(0);
cvDestroyWindow("B:");
cvReleaseImage(&result[1]);
Posted
Updated 25-May-13 5:26am
v4
Comments
Santhosh G_ 25-May-13 10:11am    
Please provide code of method()

C#
for(int i=0;i<160;i++)
{
    result[i]=cvCreateImage(cvGetSize(Segimg), 8, 1);
}

Here 160 images are allocated and assigned to result[0] to result[159].

C++
*result=method();

Here result[0] is overwritten with address returned from method.
If result[0] is not properly deleted by calling cvReleaseImage, it will create memory leak.

And all allocated images should be deleted by calling cvReleaseImage like this.

C#
for(int i=0;i<160;i++)
{
    cvReleaseImage(&result[i]);
}
 
Share this answer
 
v2
Comments
123ezone 26-May-13 5:20am    
I want to create an array of images using opencv(IplImage) and the size of the array depends on input image.So initially I don't know the size.Can I create that array like this.
IplImage *result[];
And if I want to initialize the image set, since I don't knw the size how can I do that.Can I do it like this?
for(int i=0;i<.....;i++)
{
result[i]=cvCreateImage(cvGetSize(img), 8, 1);
}
Santhosh G_ 26-May-13 5:34am    
If size is unknown, Use dynamic data structures like list or vector, and add each items as you needed.

But here you can allocate the array before for loop. Isn't it ?
*result=method();

produces the same effect of
result[0]=method();

Hence you are basically overwriting result[0] pointer without releasing the pointed memory.
 
Share this answer
 
Comments
123ezone 26-May-13 4:01am    
I want to create an array of images using opencv(IplImage) and the size of the array depends on input image.So initially I don't know the size.Can I create that array like this.

IplImage *result[];

And if I want to initialize the image set, since I don't knw the size how can I do that.Can I do it like this?

for(int i=0;i<.....;i++){
result[i]=cvCreateImage(cvGetSize(img), 8, 1);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900