Memory allocation and release of "OpenCV" images, copying images and setting image ROI region

Source: Internet
Author: User

(1) Allocate memory to a new image:

iplimage* cvcreateimage (cvsize size, int depth, int channels); size     -image width, height. Depth   -the bit depth of the image element, which can be one of the following:              ipl_depth_8u-Unsigned 8-bit integer             ipl_depth_8s-Signed 8-bit integer             ipl_depth_16u-unsigned 16-bit integer             ipl_depth_16s-signed 16-bit integer             ipl_ Depth_32s-Signed 32-bit integer             ipl_depth_32f-single-precision floating-point              number ipl_depth_64f-double-precision floating-point numbers channels-the amount of color channels per element (pixel). can be 1, 2, 3 or 4. Channels are cross-stored For example, the usual color image data arrangement is: B0G0 r0 B1 g1 R1 ...

Example

Iplimage*img=cvcreateimage (Cvsize (640,480), ipl_depth_8u,1);

(2) Release the Image:

Iplimage*img=cvcreateimage (Cvsize (640,480), ipl_depth_8u,1); Cvreleaseimage (&img);

(3) Copy Image:

Iplimage*img1=cvcreateimage (Cvsize (640,480), ipl_depth_8u,1); Iplimage*img2;img2=cvcloneimage (IMG1);  Note that images obtained by Cvcloneimage are also released with Cvreleaseimage, otherwise prone to memory leaks

(4) setting, acquiring, and releasing ROI for an area of interest:

Set the image Roi region void  Cvsetimageroi (iplimage* image, Cvrect rect);//Release the image based on the given matrix settings roivoid  Cvresetimageroi ( iplimage* image);//Returns the ROI coordinate cvrect cvgetimageroi (const iplimage* image);

Most OPENCV functions support roi,region of interests, and after the ROI is set, the function's processing of the image will only be applied to the ROI region.

Memory allocation and release of "OpenCV" images, copying images and setting image ROI region

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.