This forum is disabled, please visit https://forum.opencv.org

1 | initial version |

assuming, you have 2 images A and B of equal size, 3 channels each, you could first merge them like this:

```
vector<Mat> v = {A,B};
Mat C;
merge(v, C);
```

now C has 6 interleaved channels, and we need to add the "batch" dimension:

```
int sz[] = {1, A.rows, A.cols, 6};
Mat blob(4, sz, CV_32F, C.data);
```

2 | No.2 Revision |

assuming, you have 2 (float) images A and B of equal size, 3 channels each, you could first merge them like this:

```
vector<Mat> v = {A,B};
Mat C;
merge(v, C);
```

now C has 6 interleaved channels, and we need to add the "batch" dimension:

```
int sz[] = {1, A.rows, A.cols, 6};
Mat blob(4, sz, CV_32F, C.data);
```

3 | No.3 Revision |

assuming, you have 2 (float) images A and B of equal size, 3 channels each, you could first merge them like this:

```
vector<Mat> v = {A,B};
Mat C;
merge(v, C);
```

now C has 6 interleaved channels, and we need to add the "batch" dimension:

```
int sz[] = {1, A.rows, A.cols, 6};
Mat blob(4, sz, CV_32F, C.data);
```

but careful ! your blob does NOT hold a deep copy of the data, so C has to be kept alive during the processing !

4 | No.4 Revision |

assuming, you have 2 (float) images A and B of equal size, 3 channels each, you could first merge them like this:

```
vector<Mat> v = {A,B};
Mat C;
merge(v, C);
```

now C has 6 interleaved channels, and we need to add the "batch" dimension:

```
int sz[] = {1, A.rows, A.cols, 6};
Mat blob(4, sz, CV_32F, C.data);
```

but careful ! your blob does NOT hold a deep copy of the data, so C has to be kept alive during the processing !

EDIT: due to public demand, here's the reverse operation ;)

```
// extract 2d, 6chan Mat
Mat c2(ocv.rows, ocv.cols, CV_32FC(6), blob.ptr(0));
// split into channels
vector<Mat> v2;
split(c2,v2);
// merge back into 2 images
Mat a,b;
merge(vector<Mat>(v2.begin(), v2.begin()+3), a);
merge(vector<Mat>(v2.begin()+3, v2.end()), b);
```

5 | No.5 Revision |

```
vector<Mat> v = {A,B};
Mat C;
merge(v, C);
```

now C has 6 interleaved channels, and we need to add the "batch" dimension:

```
int sz[] = {1, A.rows, A.cols, 6};
Mat blob(4, sz, CV_32F, C.data);
```

but careful ! your blob does NOT hold a deep copy of the data, so C has to be kept alive during the processing !

EDIT: due to public demand, here's the reverse operation ;)

```
// extract 2d, 6chan Mat
Mat
```~~c2(ocv.rows, ocv.cols, ~~c2(A.rows, A.cols, CV_32FC(6), blob.ptr(0));
// split into channels
vector<Mat> v2;
split(c2,v2);
// merge back into 2 images
Mat a,b;
merge(vector<Mat>(v2.begin(), v2.begin()+3), a);
merge(vector<Mat>(v2.begin()+3, v2.end()), b);

6 | No.6 Revision |

```
vector<Mat> v = {A,B};
Mat C;
merge(v, C);
```

now C has 6 interleaved channels, and we need to add the "batch" dimension:

```
int sz[] = {1, A.rows, A.cols, 6};
Mat blob(4, sz, CV_32F, C.data);
```

EDIT: due to public demand, here's the reverse operation ;)

```
// extract 2d, 6chan Mat
Mat
```~~c2(A.rows, A.cols, ~~c2(blob.size[2], blob.size[3], CV_32FC(6), blob.ptr(0));
// split into channels
vector<Mat> v2;
split(c2,v2);
// merge back into 2 images
Mat a,b;
merge(vector<Mat>(v2.begin(), v2.begin()+3), a);
merge(vector<Mat>(v2.begin()+3, v2.end()), b);

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.