gpt4 book ai didi

opencv - 透明度中的 Alpha 值问题

转载 作者:行者123 更新时间:2023-12-02 17:13:23 25 4
gpt4 key购买 nike

我正在使用 opencv 创建水印应用程序,我无法将图像的背景设置为透明。
我正在使用此代码 Scalar colorScalar = new Scalar(255,255,255,0);
任何人都可以帮助我如何使背景透明。我正在使用PNG格式的图像。

targetMat = new Mat(targetSize, scaledImage.type(), colorScalar);
Mat waterSubmat = targetMat.submat((int)offsetY,scaledImage.height(), (int)offsetX, scaledImage.width());
scaledImage.copyTo(waterSubmat);
center = new org.opencv.core.Point(pivotX, pivotY);
Mat rotImage = Imgproc.getRotationMatrix2D(center, degreevaluechange, 1);
Mat resultMat = new Mat(2,3, CvType.CV_32FC1);
colorScalar = new Scalar(255,255,255,0);
Imgproc.warpAffine(targetMat, resultMat, rotImage, targetSize, Imgproc.INTER_AREA, Imgproc.BORDER_CONSTANT, colorScalar);
scaledImage = resultMat.clone();

最佳答案

如果您想使用 alpha channel 加载您的 PNG 图像并因此以透明方式加载您的图像,您必须使用以下代码:

imread("image.png",-1)

您可以在此处的 opencv 文档中找到更多信息:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#imread

关于opencv - 透明度中的 Alpha 值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23754070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com