2012-10-08 48 views
0

我需要在较大的图像中放置较小的图像。较小的图片应以较大的图片为中心。我正在使用C#和OpenCV,有谁知道如何做到这一点?在较大的图像中放置较小的图像。

+0

您是否在使用Emgu CV? – Krish

+0

克里什没有。 我正在使用OpenCV和C#。你有什么想法来帮助我吗? –

回答

0

检查this post。同样的问题,相同的解代码是用于C++,但你可以解决它。

1

有一个helpful post关于水印图像,可能会帮助你。我认为它与你正在做的事情非常接近相同的过程。

此外,请务必在CodeProject上检查this article,以查看使用GDI +的另一个示例。

0

这个工作对我来说

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

EmguCV当然

0

的上述答案是伟大的!这是一个将水印添加到右下角的完整方法。

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; 
    } 
相关问题