Cvcloneimage () Memory leakage solution, differences between cvcloneimage () and cvcopy ()

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.