您的位置:首页 > 运维架构

OpenCV学习之数据类型

2012-04-10 15:57 183 查看
1. CvPoint

typedef struct CvPoint

{

int x;

int y;

}

CvPoint;

CvPoint用来描述图像中的像素点。

2. CvSize

typedef struct

{

int width;

int height;

}

CvSize;

CvSize用来描述图像的尺寸。

3. CvRect

typedef struct CvRect

{

int x;

int y;

int width;

int height;

}

CvRect;

CvRect用来描述图像的一个区域。

4. CvScalar

typedef struct CvScalar

{

double val[4];

}

CvScalar;

CvScalar用来描述RGBA值。

所有的数据类型都有个以其名称来定义的构造函数,例如:CvSize,它的构造函数位cvSize,只是首字母是小写的。

5. 矩阵类型CvMat

typedef struct CvMat

{

int type;

int step;

/* for internal use only */

int* refcount;

int hdr_refcount;

union

{

uchar* ptr;

short* s;

int* i;

float* fl;

double* db;

} data;

#ifdef __cplusplus

union

{

int rows;

int height;

};

union

{

int cols;

int width;

};

#else

int rows;

int cols;

#endif

}

CvMat;

CvMat结构成员说明:

type:为矩阵元素的类型,像这种形式:CV_<bit_depth>(S|U|F)C<number_of_channels>,例如:CV_8UC1,表示8位无符号一元组。

step:行长度,包含4字节对齐的部分。

data:矩阵数据域指针,因为矩阵元素数据类型可以是任何基本的数据类型,所以它这里采用了个联合体。

rows:矩阵行数。

cols:矩阵列数。

不要以为矩阵是很复杂的东西,它的数据也是连续存储的,只不过它有个rows和cols,相当于有两把尺子,cols这么多表示一行,总共rows行。

6. IplImage

typedef struct _IplImage

{

int nSize; /* sizeof(IplImage) */

int ID; /* version (=0)*/

int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */

int alphaChannel; /* Ignored by OpenCV */

int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,

IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */

char colorModel[4]; /* Ignored by OpenCV */

char channelSeq[4]; /* ditto */

int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.

cvCreateImage can only create interleaved images */

int origin; /* 0 - top-left origin,

1 - bottom-left origin (Windows bitmaps style). */

int align; /* Alignment of image rows (4 or 8).

OpenCV ignores it and uses widthStep instead. */

int width; /* Image width in pixels. */

int height; /* Image height in pixels. */

struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */

struct _IplImage *maskROI; /* Must be NULL. */

void *imageId; /* " " */

struct _IplTileInfo *tileInfo; /* " " */

int imageSize; /* Image data size in bytes

(==image->height*image->widthStep

in case of interleaved data)*/

char *imageData; /* Pointer to aligned image data. */

int widthStep; /* Size of aligned image row in bytes. */

int BorderMode[4]; /* Ignored by OpenCV. */

int BorderConst[4]; /* Ditto. */

char *imageDataOrigin; /* Pointer to very origin of image data

(not necessarily aligned) -

needed for correct deallocation */

}

IplImage;

IplImage是通常所说的“图像”进行编码的基本结构。遵循面向对象设计思想,IplImage由CvMat派生,CvMat由CvArr派生。在函数原型中会经常看到CvArr*,当它出现时,便可以将CvMat*或IplImage*传递到程序。
重要成员说明:

width:就是经常说的图像像素宽度。

height:图像像素高度。

depth:表示图像像素类型,可以取如下值:

IPL_DEPTH_8U,IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F和IPL_DEPTH_64F
分别表示8位无符号,8位有符号,16位有符号,32位有符号,32位浮点,64位浮点数。

nchannels:可取值1,2, 3, 4,表示通道数。
origin:有两种取值,IPL_ORIGIN_TL和IPL_ORIGIN_BL,分别设置坐标原点的位置于图像的左上角和左下角。

widthStep:和矩阵的step参数类似。

imageData:数据域指针,这是和矩阵最大的不同,矩阵元素数据可以是任何数据类型,而IplImage是unsigned char类型的,表示的是像素数据。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: