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:
- Read an image from source (webcam/video file etc.)
- Preprocess it (optional, but can be proven useful)
- Extract from a region (e.g. from the head of a person) points to track. You can do this automatically using the
cvGoodFeaturesToTrack
method. - 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 ;).
Author by
Kaveh Shahbazian
Programming, FunctionalProgramming, Learning continuously about Clean Code, Teamwork, TDD, DDD/IDD, and Technical Debt
Updated on June 16, 2022Comments
-
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 almost 13 yearsThanks 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 almost 13 yearsyou can take the bounding rectangle of the regions eg: i54.tinypic.com/15d5ncj.png
-
Kaveh Shahbazian almost 13 yearsWould you please guide me how to take bounding rectangle?
-
Matyas almost 13 yearsyou 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 almost 13 yearsThanks! 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 almost 13 yearsIf 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)