Skip to main content

Tracking objects in a video

Import a sample video

source: https://www.azonano.com/nanotechnology-video-details.aspx?VidID=47

Download original notebook
video = (* import a video here *)

Extract a frame and find the features

With[{frames = VideoExtractFrames[video, {1,2}]},
  HighlightImage[frames//First, {Yellow, ImageFeatureTrack[frames, MaxFeatures->25, Tolerance->0.01] // First}]
]
(*VB[*)(FrontEndRef["383b2c5f-67cb-451c-b4ea-38be171175d1"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKG1sYJxklm6bpmpknJ+mamBom6yaZpCbqGlskpRqaGxqam6YYAgCFyhWb"*)(*]VB*)

Track them in all frames

features = ImageFeatureTrack[VideoExtractFrames[video, All], MaxFeatures->25, Tolerance->0.01];
tracks = Map[DeleteMissing, features // Transpose];
ListLinePlot[tracks, AspectRatio -> 1, PlotRange -> All]
(*VB[*)(FrontEndRef["e99d3a72-1456-46ce-8948-39ba26b6fdcf"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKp1paphgnmhvpGpqYmumamCWn6lpYmljoGlsmJRqZJZmlpSSnAQB9+RW8"*)(*]VB*)

Overlay plot with our image

HighlightImage[VideoExtractFrames[video, 1], {
  Yellow, Opacity[0.3], Line /@ tracks
}];

Magnify[%, 2]
(*BB[*)((*VB[*)(FrontEndRef["ae07abff-e730-4405-9f46-3e9973c4ad50"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKJ6YamCcmpaXpppobG+iamBiY6lqmmZjpGqdaWpobJ5skppgaAACMFRWp"*)(*]VB*))(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KWlMIB4HkAguqcxJdcqvgIiA5INKc1KLeYEM38T0vMy0zOTEksz8PIg8K5AIycxNLc4EczmBhGdeRmpRZklqCpoJPGDDizIL/PM88wpKS8B63RJzilMB244hlA=="*)(*]BB*)