庞峰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


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值