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!