本文主要是介绍庞峰Opencv学习(二)--对矩阵结构体CvMat的基本操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. CvMat结构体:(注释)typedef struct CvMat
{
int type; //数据类型以 CV_N{U|S|F}C{1,2,3...}表示
int step; //表示一行有多少个字,在32位操作系统中,一个字为4个字节
/* 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. CvMat的创建方法:(注释)
CvMat *pmat1;
pmat1 = cvCreateMat(4,5,CV_32FC3); //1.create directly
CvMat *pmat2;
pmat2=cvCreateMatHeader(4,5,CV_8UC1);//2.only create a wrapper for CvMat,
//not to allocate the memory for data
cvCreateData(pmat2); //allocate the memory for data
float data[4]={1,3,7,4};
CvMat pmat3;
cvInitMatHeader(&pmat3,2,2,CV_32FC1,data);//3.initialize the CvMat,and
//the data pointer point to the array
CvMat *pmat4;
pmat4 = cvCloneMat(pmat2);//4. clone the CvMat,
//but the data address is different
3. CvMat的属性获取:(注释)
int type=cvGetElemType(t); //get the type number
int size[10];
int dims = cvGetDims(t,size); //size store the dimensions eg. rows,cols....
int x = cvGetDimSize(t,0); //rows
int y = cvGetDimSize(t,1); //cols
这篇关于庞峰Opencv学习(二)--对矩阵结构体CvMat的基本操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!