Ask Your Question
1

How to get Size for N (N>2) dimensional Mat

asked 2013-02-28 07:49:40 -0600

artanis gravatar image

updated 2013-02-28 21:47:48 -0600

Hi all,

Sorry to disturb you.

As we know Mat::size() will work only the dimension of Mat is not greater than 2. Could you please tell me how we can get the size if the dimension is greater than 2 ?

For example, if I create a Mat by Mat(3, (int[]) {3,4,5}, CV_64F), we can get its dimension via Mat::dims or Mat::size.p[-1], but how can we get its size, i.e. {3,4,5} ?

Thank you.

SOLVED
Use Mat::size and cast it into const int*, then we can get an array to indicate the length of each dimension.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-03-01 13:01:35 -0600

xaffeine gravatar image

You can use the non-function size member of the Mat object. Also the dims member is handy, as follows. The size member is defined as an MSize object, but you can access it like an array. This solution requires NO CASTING.

const cv::Mat & srcImage;
int nDims = srcImage.dims;
int lastDim = srcImage.size[nDims-1];
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-28 07:49:40 -0600

Seen: 7,565 times

Last updated: Mar 01 '13