When cvcloneimage () is used each time, the compiler allocates a new memory space and does not overwrite the previous content. Therefore, if the memory is used in a loop, it will be quickly reduced. cvrelease must be used to release each time it is used up.
The solution is to use the cvcopy function instead.
Cvcopy (psrcimg, pimg, null); // replace pimg = cvcloneimage (psrcimg );
Space must be allocated during pimg initialization; otherwise, the above functions cannot be executed.
Pimg = cvcreateimage (cvsize (imgwidht, imgheight), ipl_depth_8u, 3 );
Differences between cvcopy () and cvcloneimage () in opencv:
The cvcopy prototype is:
Void cvcopy (const cvarr * SRC, cvarr * DST, const cvarr * mask = NULL );
Before using this function, you must use a function such as cvcreateimage () to open a piece of memory and then pass it to DST. Cvcopy copies the data in SRC to the DST memory.
The prototype of cvcloneimage is:
Iplimage * cvcloneimage (const iplimage * image );
You do not need to open up the memory before using the function. This function will open a memory, copy the data in the image, and return the data in the memory to you.
Clone is to copy all the data, that is, whether or not you set the ROI, COI, and other parameters that affect the copy, clone will be intact.
Copy is different. Only the ROI region is copied.
After clone replication is used, the source image disappears in the memory, and the copied image also changes. When the source image disappears, the copied image remains unchanged.