Why does .clone() doesn't copy rows?

I got this code:

cv::Mat mat { {3, 3, 3},  CV_8UC3};
auto mat2 = mat.clone(); 

To have two copies of the same matrix, but mat2.rows != mat.rows`, looks like data has been correctly copied, but all metadata doesn’t, which is the correct way to copy a matrix into an other new one (with out sharing data, acutally copying it).

this makes a 3x3x3 3d cube of bgr pixels
(are you sure you wanted it that way ?).

you cannot access multidimensional Mat’s using rows and cols, or size(), which are limited to 2d functionality

instead use mat.size (w/o braces !) as in

cout << mat.size << mat2.size << endl;

or :

mat.size[0] == mat2.size[0]

and you’ll see, that cloning your Mat worked fine :wink:

1 Like