首先看一下IplImage的數據結構:
IplImage---Image Processing Library_Image
<span style="font-family:Microsoft YaHei;">typedef struct _IplImage
{
int nSize; /* IplImage大小 */
int ID; /* 版本 (=0)*/
int nChannels; /* 大多數OpenCV支持1、2、3或4個通道*/
int alphaChannel; /* 被OpenCV忽略*/
int depth; /* 像素的位深度,支持如下格式: IPL_DEPTH_8U、IPL_DEPTH_8S, IPL_DEPTH_16S、IPL_DEPTH_32S、IPL_DEPTH_32F、IPL_DEPTH_64F*/
charcolorModel[4]; /* 被OpenCV忽略*/
charchannelSeq[4]; /* 被OpenCV忽略*/
int dataOrder; /* 0表示交叉存取顏色通道, 1表示分開的顏色通道,只有cvCreateImage可以創建交叉存取圖像*/
int origin; /*圖像原點位置,0表示頂-左結構(左上角),1表示底-左結構(右下角) */
int align; /* 圖像行排列方式(4或者8),被OpenCV忽略,使用widthStep代替*/
int width; /* 圖像寬相位數*/
int height; /* 圖像高相位數*/
struct_IplROI*roi; /* 圖像感興趣區域,當該值非空時,只對該區域處理*/
struct_IplImage*maskROI; /* 在OpenCV中必須爲NULL */
void *imageId; /* 在OpenCV中必須爲NULL */
struct_IplTileInfo*tileInfo; /* 在OpenCV中必須爲空 */
int imageSize; /* 圖像數據大小(在交叉存取格式下imageSize = image->height*image->widthStep) 單位字節)*/
char*imageData; /* 指向排列的圖像數據*/
int widthStep; /* 排列的圖像行大小,單位字節 */
int BorderMode[4]; /* 被OpenCV忽略*/
int BorderConst[4]; /* 被OpenCV忽略*/
char*imageDataOrigin; /* 指針指向一個不同的圖像數據結構(不是必須排列的) 是爲了糾正圖像內存分配準備的 */
}IplImage;
</span>
</pre><pre name="code" class="cpp"><span style="font-family:Microsoft YaHei;">typedef struct CvMat
{
int type; /*創建的圖像元素類型(uchar,short,int,float,double)*/
int step; /*每一行長度,以byte記算*/
int* refcount; /*指針的引用計數器; 陣列指向用戶分配的數據時,指針爲 NULL*/
union{
uchar* ptr; /*Data pointer for an unsigned char matrices*/
short* s; /* Data pointer for a short matrices*/
int* i; /* Data pointer for an integer matrices */
float* f; /* Data pointer for a float matrices */
double* db; /* Data pointer for a double matrices */
}data; /*Data pointer*/
union{
int rows;
int height;
};
union{
int cols;
int width;
};
}CvMat;</span>
解釋一下OpenCV中圖像通道數的問題:
YCrCb也有類似壓縮情況。