1

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(width, height), IPL_DEPTH_8U, 3);
    }
    
    ...
    

    }

  • Option 2:

    IplImage* image1 = NULL;

    ...

    IplImage* picture_sintetica(...){

    ...
    
    image1 = cvCreateImage( cvSize(width, height), 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?

Thanks so much!

VirMarGu
  • 41
  • 8

1 Answers1

0

Starting from Doubt3, according with opencv documentation, you should use cvCloneImage when you need a full copy of an image (including header, data and ROI).

Doubt1: looking at your code, there'are no reason to think image1 should created many times, unless your code is in a cicle.

Doubt2: i suggest to take a look to this answer

Community
  • 1
  • 1
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
  • Thanks! The method named picture_sintetica is called every time that a frame of a video is decoded. The frame will be a param of the function and into this method it will call to OpenCV functions and it will create different images. Therefore, i think that every time a frame is decoded, the image1 will be created in the option 2 and with the option 1 when the second frame is decoded and picture_sintetica is called, image1 isn't NULL and overwrite the last values in image1. – VirMarGu Oct 22 '13 at 14:35