使用emgu.cv的Alpha合成图像

Emgu.CV(Nuget包2.4.2)并没有我能告诉实现OpenCV中可用的gpu :: alphaComp方法。

因此,当尝试实现这种特定类型的复合时,C#中的速度令人难以置信,这样它占用了我应用程序总CPU容量的80%。

这是我原来的解决方案,表现非常糟糕。

static public Image Overlay( Image image1, Image image2 ) { Image result = image1.Copy(); Image src = image2; Image dst = image1; int rows = result.Rows; int cols = result.Cols; for (int y = 0; y < rows; ++y) { for (int x = 0; x < cols; ++x) { // http://en.wikipedia.org/wiki/Alpha_compositing double srcA = 1.0/255 * src.Data[y, x, 3]; double dstA = 1.0/255 * dst.Data[y, x, 3]; double outA = (srcA + (dstA - dstA * srcA)); result.Data[y, x, 0] = (Byte)(((src.Data[y, x, 0] * srcA) + (dst.Data[y, x, 0] * (1 - srcA))) / outA); // Blue result.Data[y, x, 1] = (Byte)(((src.Data[y, x, 1] * srcA) + (dst.Data[y, x, 1] * (1 - srcA))) / outA); // Green result.Data[y, x, 2] = (Byte)(((src.Data[y, x, 2] * srcA) + (dst.Data[y, x, 2] * (1 - srcA))) / outA); // Red result.Data[y, x, 3] = (Byte)(outA*255); } } return result; } 

有没有办法在C#中优化上述内容?

我还看了一下使用OpencvSharp,但这似乎并没有提供对gpu :: alphaComp的访问。

有没有可以进行alpha合成的OpenCV C#包装器库?

AddWeighted不能做我需要做的事情。

虽然相似,但这个问题没有提供答案

这么简单。

  public static Image Overlay(Image target, Image overlay) { Bitmap bmp = target.Bitmap; Graphics gra = Graphics.FromImage(bmp); gra.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; gra.DrawImage(overlay.Bitmap, new Point(0, 0)); return target; }