2015-04-07 95 views
0

将两个子图像添加到一个新图像中我有两个不同尺寸的图像,我想创建另一个包含它们的大图像垂直。使用emgu cv

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

返回的图像是一个黑色的图像,不包含这两个图像,请帮助我哪里的问题?

谢谢。

+0

什么问题? – GPPK

+0

我解决了这个问题,正确的方法是把我的答案放在这里或删除我的问题帖子或什么? – Abdo

+0

将其发布为答案 – GPPK

回答

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

此解决方案不适用于大型位图(10600瓦x 9980小时) –

3

你的做法是正确的。您只需删除投资回报率。只是在结尾处加上:

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;