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
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["http://community.wolfram.com/c/portal/getImageAttachment?filename=freefall.gif&userId=11733"];



Now note how nicely one object is tracked and another isn’t because it was not originally in the very 1st frame.
DynamicModule[{res},
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["http://community.wolfram.com/c/portal/getImageAttachment?filename=dice.gif&userId=11733"];



ListAnimate[Show[ImageCrop[#, {200, 200}], Graphics[{Blue, PointSize[.05],
      Point[ComponentMeasurements[MorphologicalComponents[
          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
You probably want to check out ImageFeatureTrack ( http://reference.wolfram.com/mathematica/ref/ImageFeatureTrack.html ) and its friend, ImageCorrespondingPoints ( http://reference.wolfram.com/mathematica/ref/ImageCorrespondingPoints.html ).
POSTED BY: Jari Kirma
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).

Example:

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

gives

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

Group Abstract Group Abstract