背景减法c#emgucv

时间:2015-04-13 14:33:32

标签: c# emgucv

我用emguCV开始冒险。我想写一个简单的算法来检测移动的物体。我尝试减去背景但图像全黑。

public Form1()
{
   previous = grabber.QueryFrame();
   Application.Idle += new EventHandler(FrameGrabber27);
}

void FrameGrabber27(object sender, EventArgs e)
{
   Image<Bgr, Byte> output = new Image<Bgr,Byte>(300,300);
   Image<Bgr, Byte> actual = grabber.QueryFrame();

   int width = output.Width;
   int height = output.Height;

   image27.Image = grabber.QueryFrame();
   ibProcessed.Image = actual;
   for (int i = 0; i < width; i++)
   {
       for (int j = 0; j < height; j++)
       {                       
           if ((actual[j, i].Blue == previous[j, i].Blue) && ( actual[j, i].Red == previous[j, i].Red)&&(actual[j, i].Green == previous[j, i].Green))                    
           {
               output[j, i] =newBgr(0,0,0);                             
           }
           else
           {                         
               output[j, i] = new Bgr(255, 255, 255);
           }
       }
   }
   im.Image = output;

1 个答案:

答案 0 :(得分:0)

  1. 为什么要将输出图像的大小设置为300 * 300,而不是设置为actual.width * actual.height?
  2. output[j, i] =newBgr(0,0,0);我希望你的项目中没有忘记空间吗?
  3. ((actual[j, i].Blue == previous[j, i].Blue) && ( actual[j, i].Red == previous[j, i].Red)&&(actual[j, i].Green == previous[j, i].Green))这几乎总是如此,即使网络摄像头和场景是静态的,两帧之间的每个像素上的颜色总会有微小的变化。
  4. OpenCV提供2个背景扣除功能:Here it is