1 | initial version |
you will need to copy memory for this, it cannot be done simply by tweaking offsets
Mat hwc = .... // src
int sz[] = {c,h,w};
Mat chw(3, sz, hwc.type()); // dst
// here's the trick: split it into existing, preallocated planes:
vector<Mat> planes(c);
for (size_t i=0; i<c; i++) {
planes[i] = Mat(h, w, chw.depth(), chw.ptr<float>(0,i)); // warn: hardcoded type !
}
split(hwc, planes);
2 | No.2 Revision |
you will need to copy memory for this, it cannot be done simply by tweaking offsets
Mat hwc = .... // src
int sz[] = {c,h,w};
Mat chw(3, sz, hwc.type()); // dst
// here's the trick: split it into existing, preallocated planes:
vector<Mat> planes(c);
for (size_t i=0; i<c; i++) {
planes[i] = Mat(h, w, chw.depth(), chw.ptr<float>(0,i)); chw.ptr<float>(i)); // warn: hardcoded type !
}
split(hwc, planes);
3 | No.3 Revision |
you will need to copy memory for this, it cannot be done simply by tweaking offsets
Mat hwc = .... // src
int sz[] = {c,h,w};
Mat chw(3, sz, hwc.type()); hwc.depth()); // dst
// here's the trick: split it into existing, preallocated planes:
vector<Mat> planes(c);
for (size_t i=0; i<c; i++) {
planes[i] = Mat(h, w, chw.depth(), chw.ptr<float>(i)); // warn: hardcoded type !
}
split(hwc, planes);