【问题标题】:Putting a smaller image within a larger image.将较小的图像放入较大的图像中。
【发布时间】:2012-10-08 18:08:42
【问题描述】:

我需要将较小的图像放在较大的图像中。较小的图片应该在较大的图片中居中。我正在使用 C# 和 OpenCV,有人知道该怎么做吗?

【问题讨论】:

  • 不要。我正在使用 OpenCV 和 C#。你有什么想法可以帮助我吗?
  • 在水印图像上有一个helpful post 可能会对您有所帮助。我认为它与您正在做的事情非常接近。另外,请务必在 CodeProject 上查看this article,了解另一个使用 GDI+ 的示例。

标签: c# opencv emgucv


【解决方案1】:

这对我有用

LargeImage.ROI = SearchArea; // a rectangle
SmallImage.CopyTo(LargeImage);
LargeImage.ROI = Rectangle.Empty;

当然是 EmguCV

【讨论】:

    【解决方案2】:

    上面的答案很棒!下面是一个在右下角添加水印的完整方法。

    public static Image<Bgr,Byte> drawWaterMark(Image<Bgr, Byte> img, Image<Bgr, Byte> waterMark)
        {
    
            Rectangle rect;
            //rectangle should have the same ratio as the watermark
            if (img.Width / img.Height > waterMark.Width / waterMark.Height)
            {
                //resize based on width
                int width = img.Width / 10;
                int height = width * waterMark.Height / waterMark.Width;
                int left = img.Width - width;
                int top = img.Height - height;
                rect = new Rectangle(left, top, width, height);
            }
            else
            {
                //resize based on height
                int height = img.Height / 10;
                int width = height * waterMark.Width / waterMark.Height;
                int left = img.Width - width;
                int top = img.Height - height;
                rect = new Rectangle(left, top, width, height);
            }
    
            waterMark = waterMark.Resize(rect.Width, rect.Height, Emgu.CV.CvEnum.INTER.CV_INTER_AREA);
            img.ROI = rect;
            Image<Bgr, Byte> withWaterMark = img.Add(waterMark);
            withWaterMark.CopyTo(img);
            img.ROI = Rectangle.Empty;
            return img;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-13
      • 2015-01-06
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      相关资源
      最近更新 更多