Motion tracking using Emgu CV (or OpenCV)

11,251

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 ;).

Share:
11,251
Kaveh Shahbazian
Author by

Kaveh Shahbazian

Programming, FunctionalProgramming, Learning continuously about Clean Code, Teamwork, TDD, DDD/IDD, and Technical Debt

Updated on June 16, 2022

Comments

  • Kaveh Shahbazian
    Kaveh Shahbazian almost 2 years

    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
    Kaveh Shahbazian almost 13 years
    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 :)
  • Matyas
    Matyas almost 13 years
    you can take the bounding rectangle of the regions eg: i54.tinypic.com/15d5ncj.png
  • Kaveh Shahbazian
    Kaveh Shahbazian almost 13 years
    Would you please guide me how to take bounding rectangle?
  • Matyas
    Matyas almost 13 years
    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.
  • Kaveh Shahbazian
    Kaveh Shahbazian almost 13 years
    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
  • Matyas
    Matyas almost 13 years
    If you know the number of groups, then you could do k-mean clustering 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)