OpenCV copy to Mat without transparent pixels

I have two images with the transparent background. I need to place both of these images with specific coordinates on the new OpenCV Mat with white background ( out Mat in the example below).

This is my current OpenCV code:

Mat out = new Mat(mat.size(), CvType.CV_8UC4);

out.setTo(new Scalar(255));

Mat rotatedMat = Imgcodecs.imread(partOfRotatedImageFile.getAbsolutePath(), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
Rect roi = new Rect((int) (rect.center.x - rotatedMat.width() / 2), (int) (rect.center.y - rotatedMat.height() / 2), rotatedMat.width(), rotatedMat.height());
Mat outPart = null;
try {
     outPart = out.submat(roi);
} catch (Exception e) {
     System.err.println(e.getMessage());
     continue;
}
rotatedMat.copyTo(outPart);

In case the images overlap each other - one of them replaces the another image(that was previously placed) with transparent pixels.

For example:

在这里输入图像描述

Sorry for the bad image quality, but as you may see the left image with Alpha channel (presented with green rectangle) overlaps the right two images by Alpha channel.

Is it possible to update this code to copy everything from source Mat objects to the resulting Mat object except transparent pixels?

链接地址: http://www.djcxy.com/p/89822.html

上一篇: '包含()'解决方法使用Linq到实体?

下一篇: OpenCV复制到Mat没有透明像素