OpenCV (Emgu.CV) — compositing images with alpha

后端 未结 4 1992
刺人心
刺人心 2020-12-31 20:21

I\'m using Emgu.CV to perform some basic image manipulation and composition. My images are loaded as Image.

Question #1:

4条回答
  •  礼貌的吻别
    2020-12-31 21:27

    You'll have to iterate through each pixel. I'm assuming image 1 is the frog image, and image 2 is the city image, with image1 always being bigger than image2.

    //to simulate image1.AddInPlace(image2)
     int image2w = image2.Width;
     int image2h = image2.Height;
     int i,j;
     var alpha;
     for (i = 0; i < w; i++)
     {
         for (j = 0; j < h; j++)
         {
               //alpha=255 is opaque > image2 should be used
               alpha = image2[3][j,i].Intensity;
               image1[j, i] 
                   = new Bgra(
                   image2[j, i].Blue * alpha + (image1[j, i].Blue * (255-alpha)),
                   image2[j, i].Green * alpha + (image1[j, i].Green * (255-alpha)),
                   image2[j, i].Red * alpha + (image1[j, i].Red * (255-alpha)));
          }
     }
    

提交回复
热议问题