【问题标题】:Tracking Blobs with Microsoft Kinect使用 Microsoft Kinect 跟踪 Blob
【发布时间】:2013-01-08 00:57:40
【问题描述】:

我正在开发人员计数器。为此,我在门上安装了 Microsoft Kinect。 我正在使用 C# 和 EmguCV。我已经提取了人的头部,使它们在黑色图像上显示为白色斑点。然后我在头部周围创建了一个边界框。这很好用。所以我现在每帧有多少个斑点,我现在也有它们的位置。这工作正常。但现在我想跟踪 blob,因为我想计算有多少人进出,但我不知道该怎么做。谁能帮我?问题是每一帧都会出现新的斑点,而旧的斑点可能会消失。谁能给我一个算法或者一些代码?或一张纸。 非常感谢!


当然。这是blob的代码:

using (MemStorage stor = new MemStorage())
        {



            Contour<System.Drawing.Point> contours = head_image.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL, stor);



            for (int i = 0; contours != null; contours = contours.HNext)
            {

                i++;



                //if ((contours.Area > Math.Pow(sliderMinSize.Value, 2)) && (contours.Area < Math.Pow(sliderMaxSize.Value, 2)))
                {

                    MCvBox2D box = contours.GetMinAreaRect();

                    blobCount++;

                    contour_image.Draw(box, new Bgr(System.Drawing.Color.Red), 1);


                    new_position = new System.Drawing.Point((int)(box.center.X), (int)(box.center.Y));
                    new_x = box.center.X;
                    new_y = box.center.Y;
                }

            }
        }

【问题讨论】:

  • 顺便说一句:我没有重叠。所以不必考虑它们。
  • 我们可以提供您用来获取 blob 的代码吗?

标签: c# image-processing kinect emgucv


【解决方案1】:

请参阅Emgu CV Blob Detection 了解更多信息。假设您使用的是 Emgu CV 2.1 或更高版本,那么答案将起作用。如果您使用的是 1.5 或更高版本,请参阅this thread,了解如何轻松检测 blob。或者看下面的代码

     Capture capture = new Capture();

     ImageViewer viewer = new ImageViewer();

     BlobTrackerAutoParam param = new BlobTrackerAutoParam();
     param.ForgroundDetector = new ForgroundDetector(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
     param.FGTrainFrames = 10;
     BlobTrackerAuto tracker = new BlobTrackerAuto(param);

     Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
     {
        tracker.Process(capture.QuerySmallFrame().PyrUp());
        Image<Gray, Byte> img = tracker.GetForgroundMask();
        //viewer.Image = tracker.GetForgroundMask();

        MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
        foreach (MCvBlob blob in tracker)
        {
           img.Draw(Rectangle.Round(blob), new Gray(255.0), 2);
           img.Draw(blob.ID.ToString(), ref font, Point.Round(blob.Center), new Gray(255.0));
        }
        viewer.Image = img;
     });
     viewer.ShowDialog();

希望这会有所帮助!

编辑

我认为您应该每十帧左右(大约每秒 3 次)使用此代码并执行以下操作:

     Capture capture = new Capture();

     ImageViewer viewer = new ImageViewer();

     BlobTrackerAutoParam param = new BlobTrackerAutoParam();
     param.ForgroundDetector = new ForgroundDetector(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
     param.FGTrainFrames = 10;
     BlobTrackerAuto tracker = new BlobTrackerAuto(param);
     int frames = 0;
     Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
     {
        frames++;//Add to number of frames
        if (frames == 10)
        {
        frames = 0;//if it is after 10 frames, do processing and reset frames to 0
        tracker.Process(capture.QuerySmallFrame().PyrUp());
        Image<Gray, Byte> img = tracker.GetForgroundMask();
        //viewer.Image = tracker.GetForgroundMask();

        int blobs = 0;

        MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
        foreach (MCvBlob blob in tracker)
        {
           //img.Draw(Rectangle.Round(blob), new Gray(255.0), 2);
           //img.Draw(blob.ID.ToString(), ref font, Point.Round(blob.Center), new Gray(255.0));
           //Only uncomment these if you want to draw a rectangle around the blob and add text
           blobs++;//count each blob
        }
        blobs = /*your counter here*/;
        blobs = 0; //reset 
        viewer.Image = img;//get next frame
     });
     viewer.ShowDialog();

编辑 2

听起来您只想识别 blob,听起来您想要McvBlob.ID。这是 blob 的 ID,您可以检查哪些 ID 仍然存在,哪些不存在。我仍然会每十帧执行一次,以免减慢速度。您只需要一个简单的算法来观察 ID 是什么,以及它们是否已更改。我会将 ID 存储在 List&lt;string&gt; 中,并每隔几帧检查该列表是否有更改。示例:

List<string> LastFrameIDs, CurrentFrameIDs;

         Capture capture = new Capture();

     ImageViewer viewer = new ImageViewer();

     BlobTrackerAutoParam param = new BlobTrackerAutoParam();
     param.ForgroundDetector = new ForgroundDetector(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
     param.FGTrainFrames = 10;
     BlobTrackerAuto tracker = new BlobTrackerAuto(param);
     int frames = 0;
     Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
     {
        frames++;//Add to number of frames
        if (frames == 10)
        {
        frames = 0;//if it is after 10 frames, do processing and reset frames to 0
        tracker.Process(capture.QuerySmallFrame().PyrUp());
        Image<Gray, Byte> img = tracker.GetForgroundMask();
        //viewer.Image = tracker.GetForgroundMask();

        int blobs = 0, i = 0;

        MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
        foreach (MCvBlob blob in tracker)
        {
           i++;
           //img.Draw(Rectangle.Round(blob), new Gray(255.0), 2);
           //img.Draw(blob.ID.ToString(), ref font, Point.Round(blob.Center), new Gray(255.0));
           //Only uncomment these if you want to draw a rectangle around the blob and add text
           CurrentFrameIDs.Add(blob.ID.ToString());
           if (CurrentFrameIDs[i] == LastFrameIDs[i])
               img.Draw(Rectangle.Round(blob), new Gray(0,0), 2);//mark the new/changed blob
           blobs++;//count each blob
        }
        blobs = /*your counter here*/;
        blobs = 0; //reset 
        i = 0;
        LastFrameIDs = CurrentFrameIDs;
        CurrentFrameIDs = null;
        viewer.Image = img;//get next frame
     });
     viewer.ShowDialog();

【讨论】:

  • 感谢您的回答。我正在使用 2.1 或更高版本。这是否意味着我可以使用您发布的代码?我不明白代码。它是如何工作的?是否应该每帧都执行,如果是,如何知道 blob 是否与下图中的 id 相同,以及 blob 是离开图像还是出现在图像中?
  • 你仍然可以使用我发布的代码,并且线程说某些用户使用此算法的处理速度存在问题
  • 好的,非常感谢 :) 但它是如何工作的?这应该在每一帧都执行吗?我不需要保护旧的 blob 以将它们与新的 blob 进行比较吗?我可以用这种方法绘制轨迹吗?
  • 你必须保存旧的 blob,我会每隔几帧激活一次以提高性能或每帧激活一次以提高准确性
  • 所以这不是跟踪器?这只是一种寻找斑点的方法吗?但我已经在我的 blob 周围绘制了矩形,那么我的代码有什么不同?
猜你喜欢
  • 1970-01-01
  • 2011-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
相关资源
最近更新 更多