2011-12-19 78 views
1

我使用Image.InRange从图像创建一个蒙版。为了保持最大性能,我使用Image.ROI裁剪图像,并在使用InRange方法之前。为了实际处理图像,我需要它具有与原始尺寸相同的尺寸,但对我而言,显而易见的是如何缩放图像,而不是更改保留图像的尺寸。调整图像<Gray, byte>无缩放。 Emgu CV

这里是有问题的代码:

public Image<Gray, byte> Process(Image<Bgr, byte> frameIn, Rectangle roi) 
    { 
     Image<Bgr, byte> rectFrame = null; 
     Image<Gray, byte> mask = null; 
     if (roi != Rectangle.Empty) 
     { 
      rectFrame = frameIn.Copy(roi); 
     } 
     else 
     { 
      rectFrame = frameIn; 
     } 

     if (Equalize) 
     { 
      rectFrame._EqualizeHist(); 
     } 


     mask = rectFrame.InRange(minColor, maxColor); 

     mask ._Erode(Iterations); 
     mask ._Dilate(Iterations); 

     if (roi != Rectangle.Empty) 
     { 
      //How do I give the image its original dimensions? 
     } 

     return mask; 
    } 

谢谢 克里斯

+0

你能证明你做了/把这个问题的形式是什么? – JesseBuesking 2011-12-19 04:57:50

回答

1

我会假设你希望与同样大小framIn最简单的方法是复制返回掩码面膜到与framIn大小相同的新图像。你可以,如果你的应用程序不是时间敏感的使掩码相同的大小framIn设置其投资回报率,然后做你的操作。这需要更长的时间来处理,而不是最佳做法。

无论如何,这里是希望你的代码后,如果不让我知道,我会相应地纠正它。

if (roi != Rectangle.Empty) 
{ 
    //Create a blank image with the correct size 
    Image<Gray, byte> mask_return = new Image<Gray, byte>(frameIn.Size); 
    //Set its ROI to the same as Mask and in the centre of the image (you may wish to change this) 
    mask_return.ROI = new Rectangle((mask_return.Width - mask.Width)/2, (mask_return.Height - mask.Height)/2, mask.Width, mask.Height); 
    //Copy the mask to the return image 
    CvInvoke.cvCopy(mask, mask_return, IntPtr.Zero); 
    //Reset the return image ROI so it has the same dimensions 
    mask_return.ROI = new Rectangle(0, 0, frameIn.Width, frameIn.Height); 
    //Return the mask_return image instead of the mask 
    return mask_return; 
} 

return mask; 

希望这有助于

干杯,

克里斯

+0

谢谢,完美的工作! – 2011-12-20 00:41:21