2011-12-19 38 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