将较小的图像放在较大的图像中. [英] Putting a smaller image within a larger image.

查看:107
本文介绍了将较小的图像放在较大的图像中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

上面的答案很棒!这是将水印添加到右下角的完整方法.

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;
    }

这篇关于将较小的图像放在较大的图像中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆