Cvcloneimage () The compiler allocates new memory space each time it is used, does not overwrite the previous content, so if memory usage in the loop is reduced quickly, it needs to be freed with cvrelease each time it is exhausted.
The workaround is to use the Cvcopy function instead.
Cvcopy (Psrcimg,pimg,null); Instead of pImg = Cvcloneimage (psrcimg);
PIMG must allocate space when initializing, otherwise the function above cannot be executed.
PIMG = Cvcreateimage (Cvsize (imgwidht,imgheight), ipl_depth_8u, 3);
The difference between cvcopy () and Cvcloneimage () in OpenCV:
The prototype of Cvcopy is:
void cvcopy (const cvarr* SRC, cvarr* DST, const cvarr* mask=null);
Before using this function, you must first open a memory with a function of cvcreateimage () and pass it to DST. The cvcopy will copy the data in SRC into DST memory.
The prototype of Cvcloneimage is:
iplimage* cvcloneimage (const iplimage* image);
There is no need to open up memory before using the function. This function will open a memory for itself, then copy the data in the image, and then return the memory of the data to you.
Clone is to copy all of them, that is, whether you set Roi,coi and other parameters that affect copy, clone will be intact clone.
Copy is different, only the ROI region is copied.
After copying with clone, the copied image changes when the source image disappears in memory, and the copied image does not change after the source image disappears with copy.
Citation: http://hi.baidu.com/gilbertjuly/blog/item/9e78f511fd0938f7c2ce7978.html