Ask Your Question
0

Printing Multi Dimension Mat using c++ in openCV

asked 2019-07-04 01:45:25 -0600

I have created a multi-dimension array, but I am not getting how to display the value. I am getting dim value correct but row/col variable is -1. How to display the matrix content.

int arr[4] = {4, 3, 2,5}; Mat L(4, arr, CV_8UC(1), Scalar::all(0));

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-07-04 07:33:29 -0600

berak gravatar image

updated 2019-07-04 07:34:41 -0600

rows and cols only make sense in a 2d context, with higher dimensional Mat's you'll have to look at the size member like:

cout << L.size << endl;

4 x 3 x 2 x 5

also, there are only suitable print functions for 2d Mat's, but you may "slice" your multi-dimensional Mat into planes, and visualize / print out those:

Mat slice(2, 5, CV_8U, L.ptr<uchar>(3,2)); // last element, just as an example
cout << slice << endl;

[  0,   0,   0,   0,   0;
   0,   0,   0,   0,   0]
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-07-04 01:45:25 -0600

Seen: 1,820 times

Last updated: Jul 04 '19