1

I need to put a smaller image within a larger image. the smaller picture should be centered in the larger picture. I'm working with C# and OpenCV, does anyone know how to do this?

Rui Marques
  • 8,567
  • 3
  • 60
  • 91
Rafael Arthur
  • 87
  • 3
  • 4
  • Krish not. I'm using OpenCV and C #. do you have any idea to help me? – Rafael Arthur Oct 08 '12 at 19:21
  • There is a [helpful post](https://stackoverflow.com/questions/1224653/place-watermark-image-on-other-images-c-asp-net) on watermarking images that might help you out. I assume it is pretty close to the same process to what you are doing. Also, be sure to check [this article](http://www.codeproject.com/Articles/2927/Creating-a-Watermarked-Photograph-with-GDI-for-NET) at CodeProject for another example using GDI+. – Tim Goyer Oct 08 '12 at 20:27

2 Answers2

2

this worked for me

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

EmguCV of course

oferb
  • 127
  • 1
  • 5
0

The above answer is great! Here's a complete method that adds the watermark to the lower right corner.

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;
    }
Mark
  • 1,374
  • 11
  • 12