Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve elements of a CV_32FC3 CvMat?

Tags:

c++

c

opencv

I'm creating a CvMat structure by calling

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).

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!

like image 888
Elmi Avatar asked Dec 26 '22 05:12

Elmi


1 Answers

The general way to access a cv::Mat is

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.

like image 108
LovaBill Avatar answered Dec 28 '22 19:12

LovaBill