This C++ sample has a corresponding Python sample.

Tracking using C++

The Analytics API provides two algorithms for object tracking:

Each algorithm has a corresponding sample showing how to use it:

  • metavision_spatter_tracking

  • metavision_generic_tracking

The source code of those samples can be found in <install-prefix>/share/metavision/sdk/analytics/samples/metavision_spatter_tracking and <install-prefix>/share/metavision/sdk/analytics/samples/metavision_generic_tracking when installing Metavision SDK from installer or packages. For other deployment methods, check the page Path of Samples.

Expected Output

Metavision Tracking samples visualize events and output bounding boxes around the tracked objects with an ID of the tracked object shown next to the bounding box:

Example of running Metavision Generic Tracking sample on the dataset file:

Example of running Metavision Spatter Tracking sample on the dataset file:

Setup & requirements

By default, Metavision Tracking looks for objects of at least 10x10 pixels size.

How to start

Here, we take Metavision Tracking sample as an example, however, Metavision Spatter Tracker runs in a similar way.

First, compile the sample as described in this tutorial.

To start the sample based on the live stream from your camera, run:





To start the sample based on recorded data, provide the full path to a RAW file (here, we use a file from our Sample Recordings):


./metavision_generic_tracking -i traffic_monitoring.raw


metavision_generic_tracking.exe -i traffic_monitoring.raw

To check for additional options:


./metavision_generic_tracking -h


metavision_generic_tracking.exe -h

Code Overview


Both samples implement the same pipeline:


Tracking Algorithm

The tracking algorithms consume CD events and produce tracking results (i.e. Metavision::EventSpatterCluster or Metavision::EventTrackingData). Those tracking results contain the bounding boxes with unique IDs.

These algorithms are implemented in an asynchronous way and process time slices of fixed duration. This means that, depending on the duration of the input time slices of events, the algorithms might produce 0, 1 or N buffer(s) of tracking results.

Like any other asynchronous algorithm we need to specify the callback that will be called to retrieve the tracking results when a time slice has been processed:

// Sets the callback to process the output of the spatter tracker
    [this](const Metavision::timestamp ts, const std::vector<Metavision::EventSpatterCluster> &clusters) {
        tracker_callback(ts, clusters);

Frame Generation

At this step, we generate an image where the bounding boxes and IDs of the tracked objects are displayed on top of the events.

Here, we are not using the Metavision::Pipeline utility class to implement the pipeline. As a consequence, to ease the synchronization between the events and the tracking results, the Metavision::OnDemandFrameGenerationAlgorithm class is used. This class allows us to buffer the input events (i.e. Metavision::OnDemandFrameGenerationAlgorithm::process_events()) and to generate the image on demand (i.e. Metavision::OnDemandFrameGenerationAlgorithm::generate()). After the event image is generated, the bounding boxes and IDs are rendered using the Metavision::draw_tracking_results() function.

As the output images are generated at the same frequency as the buffers of tracking results produced by the tracking algorithm, the image generation is done in the tracking algorithm’s output callbacks:

void Pipeline::tracker_callback(Metavision::timestamp ts,
                                const std::vector<Metavision::EventSpatterCluster> &trackers) {
    if (tracker_logger_)
        tracker_logger_->log_output(ts, trackers);

    if (frame_generation_) {
        frame_generation_->generate(ts, back_img_);

        Metavision::draw_tracking_results(ts, trackers.cbegin(), trackers.cend(), back_img_);

        if (video_writer_)
            video_writer_->write_frame(ts, back_img_);

        if (window_)

    if (timer_)

while the buffering of the events is done in the Metavision::Camera’s output callback:

// Connects filters
camera_->cd().add_callback([this](const Metavision::EventCD *begin, const Metavision::EventCD *end) {
    // Frame generator must be called first
    if (frame_generation_)
        frame_generation_->process_events(begin, end);

    tracker_->process_events(begin, end);


Different approaches could be considered for more advanced applications.


Finally, the generated frame is displayed on the screen, the following image shows an example of output:

Expected Output from Metavision Tracking Sample