This Python sample may be slow depending on the event rate of the scene and the configuration of the algorithm. We provide it to allow quick prototyping. For better performance, look at the corresponding C++ sample.

Tracking using Python

The Python bindings of Metavision SDK Analytics provide two algorithms for object tracking:

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



The source code of those samples can be found in <install-prefix>/share/metavision/sdk/analytics/python_samples/metavision_spatter_tracking and <install-prefix>/share/metavision/sdk/analytics/python_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.

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):


python3 -i traffic_monitoring.raw


python -i traffic_monitoring.raw

To check for additional options:


python3 -h


python -h

Code Overview


Both samples implement the same pipeline:


Tracking Algorithm

The tracking algorithms consume CD events and produce tracking results (i.e. metavision_sdk_analytics.EventSpatterClusterBuffer or metavision_sdk_analytics.EventTrackingDataBuffer). 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:


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. For that purpose, we rely on the metavision_sdk_core.OnDemandFrameGenerationAlgorithm class. This class allows us to buffer the input events (i.e. metavision_sdk_core.OnDemandFrameGenerationAlgorithm.process_events()) and to generate the image on demand (i.e. metavision_sdk_core.OnDemandFrameGenerationAlgorithm.generate()). After the event image is generated, the bounding boxes and IDs are rendered using the metavision_sdk_analytics.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:

# Output callback of the spatter tracking algorithm
def spatter_tracking_cb(ts, clusters):
    clusters_np = clusters.numpy()
    for cluster in clusters_np:
        log.append([ts, cluster['id'], int(cluster['x']), int(cluster['y']), int(cluster['width']),
    events_frame_gen_algo.generate(ts, output_img)
    draw_tracking_results(ts, clusters, output_img)
    if args.out_video:

while the buffering of the events is done in the main loop with the tracking processing:

# Process events
for evs in mv_iterator:
    # Dispatch system events to the window

    # Process events

    if window.should_close():


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