Click or drag to resize
Accord.NET (logo)

TestVideos Class

Public-Domain test videos for video processing and vision applications.
Inheritance Hierarchy
SystemObject
  Accord.DataSetsTestVideos

Namespace:  Accord.DataSets
Assembly:  Accord.Video (in Accord.Video.dll) Version: 3.8.0
Syntax
public class TestVideos
Request Example View Source

The TestVideos type exposes the following members.

Constructors
  NameDescription
Public methodTestVideos
Downloads and prepares the test videos dataset.
Top
Properties
  NameDescription
Public propertyItem
Downloads the example video with the specified name and returns the file path where it has been saved.
Public propertyVideoNames
Gets all the video names that can be passed to the GetVideo(String) method.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetVideo
Downloads the example video with the specified name and returns the file path where it has been saved.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(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.)
Public Extension MethodToTOverloaded.
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.)
Top
Remarks

This dataset contains sample videos from https://pixabay.com available under a CC0 Creative Commons (a.k.a. public domain), meaning no they are free for commercial use and no attribution is required.

Using this class, you can retrieve any of the following test videos:

Examples
// 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);
See Also