Size of Matrix OpenCV

Lakshmi Narayanan picture Lakshmi Narayanan · Dec 25, 2012 · Viewed 233k times · Source

I know this might be very rudimentary, but I am new to OpenCV. Could you please tell me how to obtain the size of a matrix in OpenCV?. I googled and I am still searching, but if any of you know the answer, please help me.

Size as in number of rows and columns.

And is there a way to directly obtain the maximum value of a 2D matrix?

Answer

Michael O picture Michael O · Dec 25, 2012
cv:Mat mat;
int rows = mat.rows;
int cols = mat.cols;

cv::Size s = mat.size();
rows = s.height;
cols = s.width;

Also note that stride >= cols; this means that actual size of the row can be greater than element size x cols. This is different from the issue of continuous Mat and is related to data alignment.