OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Fri, 01 Mar 2013 13:01:35 -0600How to get Size for N (N>2) dimensional Mathttp://answers.opencv.org/question/8242/how-to-get-size-for-n-n2-dimensional-mat/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.Thu, 28 Feb 2013 07:49:40 -0600http://answers.opencv.org/question/8242/how-to-get-size-for-n-n2-dimensional-mat/Answer by xaffeine for <p>Hi all,</p>
<p>Sorry to disturb you. </p>
<p>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 ?</p>
<p>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} ?</p>
<p>Thank you.</p>
<p><strong>SOLVED</strong> <br>
Use Mat::size and cast it into const int*, then we can get an array to indicate the length of each dimension.</p>
http://answers.opencv.org/question/8242/how-to-get-size-for-n-n2-dimensional-mat/?answer=8318#post-id-8318You 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];Fri, 01 Mar 2013 13:01:35 -0600http://answers.opencv.org/question/8242/how-to-get-size-for-n-n2-dimensional-mat/?answer=8318#post-id-8318