Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Initialize the images. Problems with the memory.

Hello,

I am implementing some methods and i'm using OpenCv functions.

I work with many frames of a video and i need to implement the best code to avoid some problems with the memory. I have some doubts:

Doubt 1: How would it be better?

- Option 1: IplImage* image1 = NULL;

...

IplImage* picture_sintetica(.. ){ ... if (image1 == NULL){ image1 = cvCreateImage( cvSize(w_i/2, h_i), IPL_DEPTH_8U, 3); } ... }

- Option 2:

IplImage* image1 = NULL;

...

IplImage* picture_sintetica(.. ){ ... image1 = cvCreateImage( cvSize(w_i/2, h_i), IPL_DEPTH_8U, 3);

...
cvReleaseImage(&image1);

}

I think that in option 2, the image1 is created many times(each time the method named picture_sintetica is called) and with the option 1 it will be created only once, but I'm not sure...and in other examples i've seen using the option 2.

Doubt 2: Is it equivalent declare the image equal to zero (IplImage* image1 = 0;), to NULL (IplImage* image1 = NULL;) o to put anything (IplImage* image1;)?

Doubt 3: When is it recommendable to use the function named cvCloneImage and when is it better to use cvCopy?

Initialize the images. Problems with the memory.

Hello,

I am implementing some methods and i'm using OpenCv functions.

I work with many frames of a video and i need to implement the best code to avoid some problems with the memory. I have some doubts:

Doubt 1: How would it be better?

- Option 1:

IplImage* image1 = NULL;

...

NULL; ... IplImage* picture_sintetica(.. ){ ... if (image1 == NULL){ image1 = cvCreateImage( cvSize(w_i/2, h_i), IPL_DEPTH_8U, 3); } ... }

}

- Option 2:

IplImage* image1 = NULL;

...

NULL; ... IplImage* picture_sintetica(.. ){ ... image1 = cvCreateImage( cvSize(w_i/2, h_i), IPL_DEPTH_8U, 3);

...
3);
...
cvReleaseImage(&image1);
}

}

I think that in option 2, the image1 is created many times(each time the method named picture_sintetica is called) and with the option 1 it will be created only once, but I'm not sure...and in other examples i've seen using the option 2.

Doubt 2: Is it equivalent declare the image equal to zero (IplImage* image1 = 0;), to NULL (IplImage* image1 = NULL;) o to put anything (IplImage* image1;)?

Doubt 3: When is it recommendable to use the function named cvCloneImage and when is it better to use cvCopy?