Emgu CV Blob Detection -Video Surveillance Example

时间:2014-02-25 17:10:02

标签: opencv blob detection emgucv

我正在尝试执行非常基本的blob检测但没有成功。只需使用VideoSurveillance示例......它编译并运行正常,但实际上根本检测不到blob。 FGDetector似乎运行良好,所以我似乎得到了一个很好的前景,但是BlobTrackerAuto.Process几乎不会导致找到blob ......即使在foregroundMask图像中看起来有一个非常突出的blob。这是一个代码片段,展示了我如何捕获和处理图像。

void ProcessFrame(object sender, EventArgs e)
  {
     Image<Bgr, Byte> frame = _cameraCapture.QueryFrame();

     frame._SmoothGaussian(3); //filter out noises

     _detector.Update(frame);

     Image<Gray, Byte> foregroundMask = _detector.ForegroundMask;                

     _tracker.Process(frame, foregroundMask);

     foreach (MCvBlob blob in _tracker)
     {
        frame.Draw((Rectangle)blob, new Bgr(255.0, 255.0, 255.0), 2);
        frame.Draw(blob.ID.ToString(), ref _font, Point.Round(blob.Center), new Bgr(255.0, 255.0, 255.0));
     }

     Image<Bgr, Byte> frameDisplay = frame.Resize(imageBox1.Width, imageBox1.Height, INTER.CV_INTER_LINEAR, false);
     Image<Gray, Byte> fgMaskDisplay = foregroundMask.Resize(imageBox2.Width, imageBox2.Height, INTER.CV_INTER_LINEAR, false);

     imageBox1.Image = frameDisplay;
     imageBox2.Image = fgMaskDisplay;
  }

这是来自该程序的示例图像,它显示(在我的天真的意见中)一个非常明显的blob未被检测到。

Screen shot from my program

似乎必须有某种方法来配置blob检测(阈值设置?),以便它知道如何区分前景和背景。

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

void ProcessFrame(object sender, EventArgs e)
  {
     Image<Bgr, Byte> frame = _cameraCapture.QueryFrame();

     frame._SmoothGaussian(3); //filter out noises

     _detector.Update(frame);

     Image<Gray, Byte> foregroundMask = _detector.ForegroundMask;                

     _tracker.Process(frame, foregroundMask);

     foreach (MCvBlob blob in _tracker)
     {
        frame.Draw((Rectangle)blob, new Bgr(255.0, 255.0, 255.0), 2);
        frame.Draw(blob.ID.ToString(), ref _font, Point.Round(blob.Center), new Bgr(255.0, 255.0, 255.0));
     }

     Image<Bgr, Byte> frameDisplay = frame.Resize(imageBox1.Width, imageBox1.Height, INTER.CV_INTER_LINEAR, false);
     Image<Gray, Byte> fgMaskDisplay = foregroundMask.Resize(imageBox2.Width, imageBox2.Height, INTER.CV_INTER_LINEAR, false);

     imageBox1.Image = frameDisplay;
     imageBox2.Image = fgMaskDisplay;
  }
相关问题