Opencv: iplimage image format in opencv

Source: Internet
Author: User

Conversion of iplimage image format and byte image data in opencv

Iplimage * iplimage;

Byte * data;

1. Get byte * image data from iplimage:

Data = iplimage-> imagedataorigin; // raw image data that is not aligned

Or

Data = iplimage-> imagedata; // aligned image data

2. Get iplimage * image data from byte *

Iplimage = cvcreateimageheader (cvsize (width, height), depth, channels );

Cvsetdata (iplimage, Data, step );

First, the cvcreateimageheader () is used to create an iplimage image header, and the size, depth, and number of channels of the image are determined.

Cvsetdata () sets the data of the iplimage image header Based on the byte * Image Data Pointer, where step specifies the iplimage Image

The number of bytes occupied by each row. For an ipl_depth_8u image of Channel 1, step can be equal to width.

1. If a new iplimage is created, iplimage * cvcreateimage (cvsize size, int depth, int

Channels), which creates a header and distributes data.

 

Note: When this new image is no longer used, call void cvreleaseimage (iplimage ** image) to set its header and number of images.

Data released!

 

2. If image data is not allocated storage space for the image header (that is, no dynamic storage space is allocated for the iplimage * pointer ),

Call iplimage * cvcreateimageheader (cvsize size, int depth, int channels) to create an image header.

Call void cvsetdata (cvarr * arr, void * data, int step) to specify the image data.

The Data Pointer of the image points to an existing image data, and there is no image data storage space allocation operation.

 

Note: When this new image is no longer used, call void cvreleaseimageheader (iplimage ** image) to convert its image

Header release!

 

3. If there are image data and image headers (for static storage space allocation by iplimage), call iplimage *

Cvinitimageheader (cvsize size, int depth, int channels) to change the image header, and then call void

Cvsetdata (cvarr * arr, void * data, int step) specifies the image data.

 

Note: Because this new image uses data from other images and existing image headers, you cannot use cvreleaseimage

You cannot use cvreleasedata to release the image data!

 

4. If you create an image from an existing image, use iplimage * cvcloneimage (const iplimage * image ).

A complete copy of the image includes the header, ROI, and data.

 

Note: When this new image is no longer used, call void cvreleaseimage (iplimage ** image) to set its header and number of images.

Data released!

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.