Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mat::at operator with single index

Although the OpenCV documents say:

Mat::at

the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays

we can use Mat::at with a single index for usual MxN matrix.

e.g.

cv::Mat m(3,3,CV_32F);
float *p1(m.at<float[3]>(0));
p1[0]=...; p1[1]=...; p1[2]=...;
cv::Vec3f &p2(m.at<cv::Vec3f>(1));
p2[0]=...; p2[1]=...; p2[2]=...;

This way is useful to me. My question is: Is this not a regular way? If OpenCV changes the implementation and restricts the above style, then I would have a trouble.

Mat::at operator with single index

Although the OpenCV documents say:

Mat::at

the variants with a single index (i) can be used to access elements of single-row or single-column 2-dimensional arrays

we can use Mat::at with a single index for usual MxN matrix.

e.g.

cv::Mat m(3,3,CV_32F);
float *p1(m.at<float[3]>(0));
p1[0]=...; p1[1]=...; p1[2]=...;
cv::Vec3f &p2(m.at<cv::Vec3f>(1));
p2[0]=...; p2[1]=...; p2[2]=...;

This way is useful to me. My question is: Is this not a regular way? If OpenCV changes the implementation and restricts the above style, then I would have a trouble.

Edited:

What I want to do is getting a row without a big overhead. I'm seeking a way lighter than m.row(i) (which takes cv::Mat overhead). I am assuming a case where the number of columns is known, like above case (3). In such a case, I think we could get a pointer to an array block (float[3] or cv::Vec3f) at i-th row.