Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you need to create a single Mat from several ones (of the same sizes and types) representing its channels, the best choice is the cv::merge() function.

In Java it looks following:

public void testMerge() {
    Mat src1 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(1));
    Mat src2 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(2));
    Mat src3 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(3));
    Mat dst  = new Mat();
    List<Mat> listMat = Arrays.asList(src1, src2, src3);

    Core.merge(listMat, dst);

    truth = new Mat(2, 2, CvType.CV_32FC3, new Scalar(1, 2, 3));
    assertMatEqual(truth, dst, EPS);
}