简体   繁体   English

检索CV_32FC3 CvMat的元素?

[英]Retrieve elements of a CV_32FC3 CvMat?

I'm creating a CvMat structure by calling 我正在通过调用创建一个CvMat结构

cvCreateMat(1,1,CV_32FC3);

This structure is filled by a subsequent OpenCV function call and fills it with three values (as far as I understand it, this is a 1x1 array with an additional depth of 3). 这个结构由后续的OpenCV函数调用填充,并用三个值填充它(据我所知,这是一个1x1数组,附加深度为3)。

So how can I access these three values? 那么如何才能访问这三个值呢? A normal call to 正常的电话

CV_MAT_ELEM(myMat,float,0,0)

would not do the job since it expects only the arrays dimensions indices but not its depth. 不会做这个工作,因为它只期望数组维度索引而不是它的深度。 So how can I get these values? 那么我怎样才能获得这些价值呢?

Thanks! 谢谢!

The general way to access a cv::Mat is 访问cv :: Mat的一般方法是

type value=myMat.at<cv::VecNT>(j,i)[channel]

For your case: 对于你的情况:

Mat mymat(1,1,CV_32FC3,cvScalar(0.1,0.2,0.3));
float val=mymat.at<Vec3f>(0,0)[0];

All of the types are defined using the class cv::VecNT where T is the type and N is the number of vector elements. 所有类型都使用类cv :: VecNT定义,其中T是类型,N是向量元素的数量。

CV_32FC3 is a three channel matrix of 32-bit floats. CV_32FC3是32位浮点数的三通道矩阵。 You can access each channel by declaring a struct element with 3 floats and using CV_MAT_ELEM . 您可以通过使用3个浮点数并使用CV_MAT_ELEM声明struct元素来访问每个通道。 For example: 例如:

typedef struct element {
        float cn1;
        float cn2;
        float cn3;
} myElement;

myElement data[N] = ...;
CvMat mat = cvMat(1, 1, CV_32FC2, data);

float channel1 = CV_MAT_ELEM(mat, float, 0, 0).cn1;
float channel2 = CV_MAT_ELEM(mat, float, 0, 0).cn2;
float channel3 = CV_MAT_ELEM(mat, float, 0, 0).cn3;

Edit: 编辑:

Another way to access each channel is by using the underlying ptr structure: 访问每个通道的另一种方法是使用底层的ptr结构:

mat.ptr<float>(x, y) [channel];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM