问题描述
我试图在UIImage上进行Floodfill,并最终使用OpenCV框架.我可以通过将颜色定义为cv :: Scalar(255,0,0)将其替换为纯色.但是,我希望选择的填充物是透明的.
I'm trying to do Floodfill on UIImage and ended up using OpenCV framework. I can replace the color with a solid color by defining the color as cv::Scalar(255,0,0). However I want the floodfill selection to be transparent.
我不知道如何在OpenCV中定义透明颜色,据我所知这是不可能的,唯一的选择是将图像合并到透明背景中.再次说明,使用纯色对Floodfill填充然后再将其与透明层合并并没有多大意义,因为结果将是填充区域中具有纯色的原始图像.如果我错了,请纠正我.
I don't know how I can define a transparent color in OpenCV and to the best of my knowledge it's not possible and the only option is to merge the image to a transparent background. Again it doesn't make much sense to Floodfill using a solid color and then merge it with a transparent layer as the result will be the original image with solid color in the fill areas.Please correct me if I'm wrong.
非常感谢您为解决此问题所提供的帮助.
Much appreciate your help in solving this.
欢呼
推荐答案
您无法在OpenCV中定义透明颜色,因为它当前不支持带有Alpha通道的图像.
You cannot define a transparent color in OpenCV since it currently do not support image with alpha channel.
但是,存在一个棘手的解决方案.您可以先参考此问题以创建您的洪水区域的遮罩.然后,您可以从此蒙版轻松计算出Alpha通道.
However, there exists a tricky solution. You may first refer to this question to create a mask of your floodfill area. Then you can easily calculate the alpha channel from this mask.
这篇关于OpenCV Floodfill-用透明像素替换像素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!