1.Opencv2.3.1的基本数据类型定义在:
../OpenCV-2.3.1/modules/core/include/opencv2/core/types_c.h中。
2.基本数据类型
(1)CvPoint、CvPoint2D32f、CvPoint3D32f定义如下:
typedef struct CvPoint
{
int x;
int y;
}
CvPoint;
/*坐标为单精度浮点型*/
typedef struct CvPoint2D32f
{
float x;
float y;
}
CvPoint2D32f;
/*3维坐标点*/
typedef struct CvPoint3D32f
{
float x;
float y;
float z;
}
CvPoint3D32f;
(2)CvSize、CvSize2D32f 图像的大小
typedef struct
{
int width;
int height;
}
CvSize;
typedef struct CvSize2D32f
{
float width;
float height;
}
CvSize2D32f;
(3)CvRect 图像的部分区域
typedef struct CvRect
{
int x;
int y;
int width;
int height;
}
CvRect;
以上数据类型都根据其名称定义构造函数
(4)CvScalar RGBA
typedef struct CvScalar
{
double val[4];
}
CvScalar;
有三个构造函数: CvScalar()需要一个、两个、三个、或者四个参数,分别赋给数组val[]中的相应元素。
CvRealScalar()需要一个参数传给val[0],其它的置为0.
CvScalarAll()需要一个参数传给val[0],其它的=val[0].
3.矩阵和图像类型
(1)IplImage:通常所说图像的基本编码结构,可以用于灰度图、彩色、或者4通道(RGB+alpha)的图像。
IplImage由CvMatM派生,CvMat由CvArr派生。
(2)CvMat矩阵结构
<1>CvMat中没有向量(vector),用列矩阵或者行矩阵代替。
<2>矩阵元素并非只能是简单的数值类型.
创建一个二维矩阵:
CvMat* cvCreateMat(int rows,int cols,int type);
para:type---CV_<bit depth><S|U|F>C<number of channels>
例如:CV_8UC1:8比特无符号的单通道图像。
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;
(2)矩阵的创建
创建矩阵有两种方法:
<1>cvCreateMat(),这个函数有多个原函数组成,如cvCreateMatHeader(),cvCreateData(),
分别创建矩阵头(不为数据分配内存)和为数据分配内存。
<2>cvCloneMat(),用已经存在的矩阵创建另一个矩阵。可以用cvReleaseMat(**CvMat)释放。
eg.
//Create a new rows by cols matrix of type ‘type’.
CvMat* cvCreateMat( int rows, int cols, int type );
// Create only matrix header without allocating data
CvMat* cvCreateMatHeader( int rows, int cols, int type );
// Initialize header on existing CvMat structure
CvMat* cvInitMatHeader(CvMat* mat,
int
rows,
int
cols,
int
type,
void* data = NULL,
int
step = CV_AUTOSTEP);
// Like cvInitMatHeader() but allocates CvMat as well.
CvMat cvMat(
int
rows,
int
cols,
int
type,
void* data = NULL
);
// Allocate a new matrix just like the matrix ‘mat’.
CvMat* cvCloneMat( const cvMat* mat );
// Free the matrix ‘mat’, both header and data.
void cvReleaseMat( CvMat** mat );
查询矩阵:
cvGetElemType();//得到矩阵的数据类型
cvGetDims();//得到矩阵维数
cvGetDimSize();//得到指定维的大小
../OpenCV-2.3.1/modules/core/include/opencv2/core/types_c.h中。
2.基本数据类型
(1)CvPoint、CvPoint2D32f、CvPoint3D32f定义如下:
typedef struct CvPoint
{
int x;
int y;
}
CvPoint;
/*坐标为单精度浮点型*/
typedef struct CvPoint2D32f
{
float x;
float y;
}
CvPoint2D32f;
/*3维坐标点*/
typedef struct CvPoint3D32f
{
float x;
float y;
float z;
}
CvPoint3D32f;
(2)CvSize、CvSize2D32f 图像的大小
typedef struct
{
int width;
int height;
}
CvSize;
typedef struct CvSize2D32f
{
float width;
float height;
}
CvSize2D32f;
(3)CvRect 图像的部分区域
typedef struct CvRect
{
int x;
int y;
int width;
int height;
}
CvRect;
以上数据类型都根据其名称定义构造函数
(4)CvScalar RGBA
typedef struct CvScalar
{
double val[4];
}
CvScalar;
有三个构造函数: CvScalar()需要一个、两个、三个、或者四个参数,分别赋给数组val[]中的相应元素。
CvRealScalar()需要一个参数传给val[0],其它的置为0.
CvScalarAll()需要一个参数传给val[0],其它的=val[0].
3.矩阵和图像类型
(1)IplImage:通常所说图像的基本编码结构,可以用于灰度图、彩色、或者4通道(RGB+alpha)的图像。
IplImage由CvMatM派生,CvMat由CvArr派生。
(2)CvMat矩阵结构
<1>CvMat中没有向量(vector),用列矩阵或者行矩阵代替。
<2>矩阵元素并非只能是简单的数值类型.
创建一个二维矩阵:
CvMat* cvCreateMat(int rows,int cols,int type);
para:type---CV_<bit depth><S|U|F>C<number of channels>
例如:CV_8UC1:8比特无符号的单通道图像。
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;
(2)矩阵的创建
创建矩阵有两种方法:
<1>cvCreateMat(),这个函数有多个原函数组成,如cvCreateMatHeader(),cvCreateData(),
分别创建矩阵头(不为数据分配内存)和为数据分配内存。
<2>cvCloneMat(),用已经存在的矩阵创建另一个矩阵。可以用cvReleaseMat(**CvMat)释放。
eg.
//Create a new rows by cols matrix of type ‘type’.
CvMat* cvCreateMat( int rows, int cols, int type );
// Create only matrix header without allocating data
CvMat* cvCreateMatHeader( int rows, int cols, int type );
// Initialize header on existing CvMat structure
CvMat* cvInitMatHeader(CvMat* mat,
int
rows,
int
cols,
int
type,
void* data = NULL,
int
step = CV_AUTOSTEP);
// Like cvInitMatHeader() but allocates CvMat as well.
CvMat cvMat(
int
rows,
int
cols,
int
type,
void* data = NULL
);
// Allocate a new matrix just like the matrix ‘mat’.
CvMat* cvCloneMat( const cvMat* mat );
// Free the matrix ‘mat’, both header and data.
void cvReleaseMat( CvMat** mat );
查询矩阵:
cvGetElemType();//得到矩阵的数据类型
cvGetDims();//得到矩阵维数
cvGetDimSize();//得到指定维的大小