Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

assuming, you have something like this (e.g. from a dnn blob):

int sz[] = {
    2, // batch size
    3, // num channels
    4, // H
    5  // W
};

Mat m(4,sz,CV_32F);
cout << m.size << endl; // note: without () !!

then you can iterate over the outer "peels", and get a 2d slice to the most inner 2d images

for (int i=0t; i<m.size[0]; i++) {
    for (int j=0; j<m.size[1]; j++) {
        // get the most inner slice:
        Mat inner(m.size[2], m.size[3], CV_32F, m.ptr<float>(i,j));
        cout << i << " " << j << " " << inner.size() << endl;       
    }
}

output:

2 x 3 x 4 x 5
0 0 [5 x 4]
0 1 [5 x 4]
0 2 [5 x 4]
1 0 [5 x 4]
1 1 [5 x 4]
1 2 [5 x 4]