Message Boards Message Boards

Tracking a point in a video

Posted 11 years ago
Is anyone aware if/how Mathematica(9.0) supports being able to track a point within a video? Essentially I have a video of something falling and want to create some data that represents how the point moves over time.  Once I have a table of positional values I can then interpret this data in the normal way.

Thanks in advance
POSTED BY: Lenny Johnson
4 Replies
Posted 11 years ago
You probably want to check out ImageFeatureTrack ( ) and its friend, ImageCorrespondingPoints ( ).
POSTED BY: Jari Kirma
There are a few examples of this and and a few methods. If you have complex perspective and background changes, then you need something like this:

Tracking Objects in an Image Sequence

Let's apply it to a .GIF file (video sequence is no different) from this site:
images = Import[""];

Now note how nicely one object is tracked and another isn’t because it was not originally in the very 1st frame.
res = Table[MapThread[HighlightImage, {images,
     ImageFeatureTrack[images, MaxFeatures -> n]}], {n, 5, 50, 5}];
Manipulate[res[[Round[features/5], frame]], {frame, 1, Length[images], 1,
   Appearance -> "Labeled"}, {{features, 5}, 5, 50, 5,
   Appearance -> "Labeled"}]]

So that used ImageFeatureTrack, but if you have static background and perspective you could write something from scratch (source):
imgs = Import[""];

ListAnimate[Show[ImageCrop[#, {200, 200}], Graphics[{Blue, PointSize[.05],
          Dilation[Binarize[ImageCrop[#, {200, 200}]], 1], .3] ,
         "Centroid"][[All, 2]]]}], ImageSize -> 300] & /@ imgs]

This free course

Image Processing: Real-World Applications

shows as one of examples - detection of period of a swinging pendulum from a video record.
POSTED BY: Vitaliy Kaurov
Posted 11 years ago
Thank you for the concise reply. At least it appears the support is in there for what I need. Ironically, at the moment I am hitting a bit of a wall importing my videos as a list of images. It seems that even though 
Import["Video Path", "Elements"]
is reporting that it can import an "ImageList" actually attempting this fails. I have tried converting my .avi to the other formats that my 3rd party software supports but I then get other errors (mp4,mpeg seem to be formats that mathematica is not keen on, or at least on my laptop). 
Is there a preferred video format that Mathematica can use? I have read around on the net and it appears that other people have had similar problems when trying to import .avi. 
POSTED BY: Lenny Johnson

You detect in two subsequent image pairs all intersting features which you want to track by using MorphologicalComponents (see above) and if they move you track them from image to image via the function Nearest (see documentation).


Nearest[{{1.5, .6}, {2, 0}, {1.25, 1.25}}, {0, 0}]


{{1.5, 0.6}}
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract