difference between size() and image matrix rowsxcolumns

96 Views Asked by At

I am a beginnner in opencv. I am trying to reshape a matrix but it doesn't seem to work.

Mat image=imread("xyz.png",1);
cout<<image.size()<<endl;
cout<<image.rows<<"x"<<image.cols<<endl;

Why are these two outputs different?

2

There are 2 best solutions below

0
On

From the OpenCV documentation:

Mat::size Returns a matrix size.

C++: Size Mat::size() const The method returns a matrix size: Size(cols, rows) . When the matrix is more than >2-dimensional, the returned size is (-1, -1).

So in the first case you are printing cols x rows and in the second case rows x cols.

0
On

From the cv documentation:

The method returns a matrix size: Size(cols, rows) . When the matrix is more than 2-dimensional, the returned size is (-1, -1).

Thus when you print the size you get cols x rows and in your second cout you get rows x cols.