6

How can I do motion tracking using Emgu CV or OpenCV? What are different ways of doing it?

I want to track objects against a fixed background.

Best Regards

Kaveh Shahbazian
  • 13,088
  • 13
  • 80
  • 139
  • What do you what to track? Objects against a fixed background? A particular colour? A particular object? Please be more specific. – damian Jun 13 '11 at 08:08
  • see http://stackoverflow.com/questions/3803061/how-to-implement-optical-flow-tracker – Sven Hecht Jan 11 '12 at 18:53

1 Answers1

7

Since I don't know Emgu CV, I would recommend OpenCV. I'd suggest you use the Lucas Kanade tracking (optical flow). You track objects by doing the following:

  1. Read an image from source (webcam/video file etc.)
  2. Preprocess it (optional, but can be proven useful)
  3. Extract from a region (e.g. from the head of a person) points to track. You can do this automatically using the cvGoodFeaturesToTrack method.
  4. Then you can track these points with cvCalcOpticalFlowPyrLK, which will give you the new positions of your tracked points.

See a better tutorial here.

If you want to understand the concepts behind these functions I would highly recommend reading Learning OpenCV - unfortunately the linked book is only a preview, with missing pages.

Anyway I am sure you can think of a place where you can get this book ;).

Matyas
  • 13,473
  • 3
  • 60
  • 73
  • Thanks for your answer. I have done what you have said with Emgu. Now how can I group points(pixels) as an object(there is more than one object)? And how can I figure out the direction? (OK; This is a new question maybe :) – Kaveh Shahbazian Jun 14 '11 at 19:18
  • you can take the bounding rectangle of the regions eg: http://i54.tinypic.com/15d5ncj.png – Matyas Jun 16 '11 at 12:01
  • Would you please guide me how to take bounding rectangle? – Kaveh Shahbazian Jun 19 '11 at 05:57
  • you take the minimum and maximum of the x and y coordinates of the points, which will be the upper left (min) respectively lower right(max) corner of the bounding box. You can figure out the direction by comparing coordinates in two (or more) consecutive frames. – Matyas Jun 20 '11 at 07:48
  • Thanks! I have done that but my problem is how to group points for different objects? I have used vectors (2 sets of points from 2 frames) but if 2 objects have same speed and direction; they would group into one. Is there any other kind of measure to group points into objects? Thank you – Kaveh Shahbazian Jun 20 '11 at 09:29
  • If you know the number of groups, then you could do [k-mean clustering](http://people.revoledu.com/kardi/tutorial/kMean/index.html) to group the points. ATM I don't have other ideas. Hope it helps (in my example I have previously selected the regions to track so I knew the groups beforehand) – Matyas Jun 21 '11 at 00:28