【问题标题】:How to copy a small image to a specified position in a large image using Emgu.CV?如何使用 Emgu.CV 将小图像复制到大图像中的指定位置?
【发布时间】:2019-09-03 12:15:12
【问题描述】:

我有几张小图像,我希望它们的像素大小正好为 100x100,无需缩放。为了实现这一点,我正在创建一个白色的 100x100 图像并将小图像复制到其中。

我的代码:

/*Small image*/
Emgu.CV.Mat Char = new Emgu.CV.Mat();
/*...fill small Image with stuff...*/

/*Create black Image (don't know how to create a White Image)*/
FinalChar = Emgu.CV.Mat.Zeros(100, 100, Emgu.CV.CvEnum.DepthType.Cv8U, 1);

/*Invert Image to become white*/
Emgu.CV.CvInvoke.BitwiseNot(FinalChar, FinalChar);

/*Copy small Image to large Image starting at row 5 and column 5*/
Char.CopyTo(FinalChar.Row(5).Col(5)); /*This is NOT working... Image 'Finalchar' is still White.*/

请不要告诉我这个帖子:OpenCV draw an image over another image 我不知道,但 rowRangecolRange 不是 Emgu.CV 的一部分。

这里有一个小例子,你可以复制试试看:

            /*Create small black image*/
        Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);

        /*Create large white image*/
        Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(20, 20, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Emgu.CV.CvInvoke.BitwiseNot(Large, Large);

        /*Copy small, black image to large white image at 5,5 - the large image should
         now contain a black rect in its center*/
        Small.CopyTo(Large.Row(5).Col(5));

        Emgu.CV.CvInvoke.NamedWindow("Output", Emgu.CV.CvEnum.NamedWindowType.AutoSize);
        Emgu.CV.CvInvoke.Imshow("Output", Large);
        Emgu.CV.CvInvoke.WaitKey();

        return;

【问题讨论】:

标签: c# image emgucv


【解决方案1】:

好的,“将较小的图像放在较大的图像中”的示例不正确 - 它只是添加了图像。因此,如果您的基本图像是黑色的,它将起作用。但是,如果您的图像是白色 (R=G=B=255) 并且您添加任何值,它将剪辑到 255。

但这对我有用:

    public static Emgu.CV.Mat EnterAtCenter(int Size = 100)
    {
        /*Create Mat and Image large, white*/
        Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(Size, Size, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Emgu.CV.CvInvoke.BitwiseNot(Large, Large);
        Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageLarge = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Large.Bitmap);

        /*Create Mat and Image small, black*/
        Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageSmall = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Small.Bitmap);

        /*Copy small Image to large Image at 5,5*/
        ImageLarge.ROI = new System.Drawing.Rectangle(5, 5, Small.Width, Small.Height);
        ImageSmall.CopyTo(ImageLarge);

        ImageLarge.ROI = System.Drawing.Rectangle.Empty;

        return ImageLarge.Mat;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-18
    • 2011-09-28
    • 2012-01-18
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    相关资源
    最近更新 更多