MatchingTracker Class |
Namespace: Accord.Vision.Tracking
The MatchingTracker type exposes the following members.
Name | Description | |
---|---|---|
MatchingTracker |
Constructs a new MatchingTracker object tracker.
|
Name | Description | |
---|---|---|
Extract |
Gets or sets a value indicating whether the tracker should
extract the object image from the source. The extracted image
should be stored in TrackingObject.
| |
RegistrationThreshold |
Gets or sets at which similarity threshold the currently
tracked object should be re-registered as the new template
to look for. This can help track slowly changing objects.
Default is 0.99.
| |
SearchWindow |
Gets or sets the current search window.
| |
Template |
Gets or sets the template being chased by the tracker.
| |
Threshold |
Gets or sets the similarity threshold to
determine when the object has been lost.
Default is 0.95.
| |
TrackingObject |
Gets the current location of the object being tracked.
|
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ProcessFrame |
Process a new video frame.
| |
Reset |
Resets this instance.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
The matching tracker will track the object presented in the search window of the first frame given to the tracker. To reset the tracker and start tracking another object, one can call the Reset method, then set the search window around a new object of interest present the image containing the new object to the tracker.
This is a very simple tracker that cannot handle size changes or occlusion.
The following example shows how to track an moving person from a video using the VideoFileReader class, how to mark the object positions using RectanglesMarker, and save those frames as individual files to the disk.
// Let's test the tracker using a sample video from // the collection of test videos in the framework: TestVideos ds = new TestVideos(basePath); string fileName = ds["walking.mp4"]; // Now, let's open the video using FFMPEG: var video = new VideoFileReader(); video.Open(fileName); // And then check the contents of one of the frames: Bitmap frame = video.ReadVideoFrame(frameIndex: 150); frame.Save(Path.Combine(basePath, "walking_frame.png")); // Let's register a template for the bike rider in gray shirt Rectangle roi = new Rectangle(x: 70, y: 105, width: 28, height: 54); // initialization var tracker = new MatchingTracker() { SearchWindow = roi, Threshold = 0.0, // never reset the tracker in case it gets lost RegistrationThreshold = 0.95 // re-register the template if we are 95% // confident that the tracked object is indeed the object we want to follow }; // Creating bitmaps and locking them is an expensive // operation. Instead, let's allocate once and reuse BitmapData bitmapData = frame.LockBits(ImageLockMode.ReadWrite); UnmanagedImage unmanagedImage = new UnmanagedImage(bitmapData); // We will create two color markers: one to show the location of the // tracked object (red) and another one to show the regions of the image // that the tracker is looking at (white). RectanglesMarker objectMarker = new RectanglesMarker(Color.Red); RectanglesMarker windowMarker = new RectanglesMarker(Color.White); // Now, for each frame of the video for (int frameIndex = 0; frameIndex < video.FrameCount; frameIndex++) { // Read the current frame into the bitmap data video.ReadVideoFrame(frameIndex, bitmapData); if (frameIndex > 150) // wait until the bike rider enters the scene { // Feed the frame to the tracker tracker.ProcessFrame(unmanagedImage); // Mark the location of the tracker object in red color objectMarker.SingleRectangle = tracker.TrackingObject.Rectangle; objectMarker.ApplyInPlace(unmanagedImage); // overwrite the frame windowMarker.SingleRectangle = tracker.SearchWindow; windowMarker.ApplyInPlace(unmanagedImage); // overwrite the frame } // Save it to disk frame.Save(Path.Combine(basePath, "frame_{0}.png".Format(frameIndex))); } frame.UnlockBits(bitmapData);