已知 IplImage* image 和 char* data
从 IplImage 到 char* :
data
=
image
->
imageData
//
对齐的图像数据
或者
data
=
image
->
imageDataOrigin
//
未对齐的原始图像数据
从 char* 到 IplImage :
image
=
cvCreateImageHeader(cvSize(width,height), depth, channels);
cvSetData(image, data, step);
cvSetData(image, data, step);
step指定IplImage图像每行占的字节数。需要注意是,在释放空间时不能直接使用cvReleaseImage,而需cvReleaseImageHeader,然后再delete data,这也是OpenCV里边“自己管理内存”的思想。
附《Intel image processing library》文档中关IplImage的声明(非OpenCV版):
typedef
struct
_IplImage
...
{
int nSize /**//* size of iplImage struct */
int ID /**//* image header version */
int nChannels;
int alphaChannel;
int depth; /**//* pixel depth in bits */
char colorModel[4];
char channelSeq[4];
int dataOrder;
int origin;
int align; /**//* 4- or 8-byte align */
int width;
int height;
struct _IplROI *roi; /**//* pointer to ROI if any */
struct _IplImage *maskROI; /**//*pointer to mask ROI if any */
void *imageId; /**//* use of the application */
struct _IplTileInfo *tileInfo; /**//* contains information on tiling */
int imageSize; /**//* useful size in bytes */
char *imageData; /**//* pointer to aligned image */
int widthStep; /**//* size of aligned line in bytes */
int BorderMode[4]; /**//* the top, bottom, left, and right border mode */
int BorderConst[4]; /**//* constants for the top, bottom, left, and right border */
char *imageDataOrigin; /**//* ptr to full, nonaligned image */
} IplImage;
int nSize /**//* size of iplImage struct */
int ID /**//* image header version */
int nChannels;
int alphaChannel;
int depth; /**//* pixel depth in bits */
char colorModel[4];
char channelSeq[4];
int dataOrder;
int origin;
int align; /**//* 4- or 8-byte align */
int width;
int height;
struct _IplROI *roi; /**//* pointer to ROI if any */
struct _IplImage *maskROI; /**//*pointer to mask ROI if any */
void *imageId; /**//* use of the application */
struct _IplTileInfo *tileInfo; /**//* contains information on tiling */
int imageSize; /**//* useful size in bytes */
char *imageData; /**//* pointer to aligned image */
int widthStep; /**//* size of aligned line in bytes */
int BorderMode[4]; /**//* the top, bottom, left, and right border mode */
int BorderConst[4]; /**//* constants for the top, bottom, left, and right border */
char *imageDataOrigin; /**//* ptr to full, nonaligned image */
} IplImage;