Tracking blobs with OpenCV

我怕爱的太早我们不能终老 提交于 2019-12-21 22:26:18

问题



I have an EMGU (openCV wrapper) program that subtracts the background from
a camera feed and extracts nice clean blobs.
Now I need something that will track these blobs and assign them with IDs.
Any suggestions/libraries ?


Thanks,
SW


回答1:


well if you have multiple objects that you would like to track you could try a Particle Filter.

Particle filters basically "disposes" particles on the image which each have a certain weight. In each time step these weights are then updated by comparing them with the actual measured value of the object at that time. Particles with high weight will then dispose more particles in its direction (with adding a slight random part on the direction) for the next time step. After a few time steps the particles will then group around the objects measured position. That's why this method is sometimes also called Survival of the fittest method...

So this whole thing builds a circle:

Initialization  ---->      Sampling
                        >             \
                       /               >
                 Updating           Prediction
                      <                /
                       \               <
                          Association

So this provides a good method of tracking objects in a given scene. One way to do multi-object tracking would be to use this one particle filter on all the objects, which would work, but has disadvantages when you try to give IDs to the objects and also when the objects cross each other since the particle clouds might lose one object and follow another one.

To solve this you could try a Mixture-Particle-Filter (by Vermaak et al. [2003]). This one tracks each of the objects by an individual Particle filter (with of course less necessary particles).

A good paper on that can be found here: http://www.springerlink.com/content/qn4704415gx65315/ (I can also supply you with several other stuff on that if you like and if you speak German I can even give you a presentation I held about that in my university a while ago)

EDIT:

Forgot to mention: Since you try to do this in OpenCV: as far as I know there is an implementation of the Condensation algorithm (the first one where you use one particle filter on the whole image) is part of the OpenCV distribution, though it might be outdated a bit. There might be newer ways of the particle filter in OpenCV directly but if not you will find a lot of results on Google if you look for OpenCV and particle filters

Hope that helps... if not, please keep asking...




回答2:


You could simply adapt one of the EMGU CV examples that makes use of VideoSurveillance namespace:

 public partial class VideoSurveilance : Form
   {
      private static MCvFont _font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
      private static Capture _cameraCapture;
      private static BlobTrackerAuto<Bgr> _tracker;
      private static IBGFGDetector<Bgr> _detector;

      public VideoSurveilance()
      {
         InitializeComponent();
         Run();
      }

      void Run()
      {
         try
         {
            _cameraCapture = new Capture();
         }
         catch (Exception e)
         {
            MessageBox.Show(e.Message);
            return;
         }

         _detector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.FGD);

         _tracker = new BlobTrackerAuto<Bgr>();

         Application.Idle += ProcessFrame;
      }

      void ProcessFrame(object sender, EventArgs e)
      {
         Image<Bgr, Byte> frame = _cameraCapture.QueryFrame();
         frame._SmoothGaussian(3); //filter out noises

         #region use the background code book model to find the forground mask
         _detector.Update(frame);
         Image<Gray, Byte> forgroundMask = _detector.ForgroundMask;
         #endregion

         _tracker.Process(frame, forgroundMask);

         foreach (MCvBlob blob in _tracker)
         {
            frame.Draw(Rectangle.Round(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));
         }

         imageBox1.Image = frame;
         imageBox2.Image = forgroundMask;

      }
   }


来源:https://stackoverflow.com/questions/4903016/tracking-blobs-with-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!