【问题标题】:Add two sub-images into one new image using emgu cv使用 emgu cv 将两个子图像添加到一个新图像中
【发布时间】:2016-09-22 23:43:40
【问题描述】:

我有两个不同尺寸的图像,我想创建另一个大图像,包括它们垂直。

private Image<Gray, Byte> newImage(Image<Gray, Byte> image1, Image<Gray, Byte> image2)
    {
        int ImageWidth = 0;
        int ImageHeight = 0;

   //get max width
        if (image1.Width > image2.Width)
            ImageWidth = image1.Width;
        else
            ImageWidth = image2.Width;

  //calculate new height
        ImageHeight = image1.Height + image2.Height;

 //declare new image (large image).
        Image<Gray, Byte> imageResult = new Image<Gray, Byte>(ImageWidth, ImageHeight);


        imageResult.ROI = new Rectangle(0, 0, image1.Width, image1.Height);
        image1.CopyTo(imageResult);
        imageResult.ROI = new Rectangle(0, image1.Height, image2.Width, image2.Height);
        image2.CopyTo(imageResult);



        return imageResult;
    }

返回的图片是黑色图片,不包含这两张图片,请帮我看看问题出在哪里?

谢谢。

【问题讨论】:

  • 我解决了这个问题,正确的方法是把我的答案放在这里或者删除我的问题帖子还是什么?。
  • 作为答案发布

标签: c# opencv emgucv


【解决方案1】:

您的方法是正确的。您只需删除 ROI。最后加上:

imageResult.ROI = Rectangle.Empty;

最终结果应该是这样的:

imageResult.ROI = new Rectangle(0, 0, image1.Width, image1.Height);
image1.CopyTo(imageResult);
imageResult.ROI = new Rectangle(0, image1.Height, image2.Width, image2.Height);
image2.CopyTo(imageResult);
imageResult.ROI = Rectangle.Empty;

【讨论】:

    【解决方案2】:

    解决方法如下:

    private Image<Gray, Byte> newImage(Image<Gray, Byte> image1, Image<Gray, Byte> image2)
    {
        int ImageWidth = 0;
        int ImageHeight = 0;
    
    //get max width
        if (image1.Width > image2.Width)
            ImageWidth = image1.Width;
        else
            ImageWidth = image2.Width;
    
    //calculate new height
        ImageHeight = image1.Height + image2.Height;
    
    //declare new image (large image).
        Image<Gray, Byte> imageResult;
    
        Bitmap bitmap = new Bitmap(Math.Max(image1.Width , image2.Width), image1.Height + image2.Height);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(image1.Bitmap, 0, 0);
                g.DrawImage(image2.Bitmap, 0, image1.Height);
    
            }
    
            imageResult = new Image<Gray, byte>(bitmap);
    
    
    
        return imageResult;
    }
    

    【讨论】:

    • 此解决方案不适用于大型位图 (10600w x 9980h)
    猜你喜欢
    • 2017-12-10
    • 2018-05-21
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 2011-07-03
    相关资源
    最近更新 更多