HAL Viewer Sample

The sample installed in <install-prefix>/share/metavision/hal/samples/metavision_hal_viewer/metavision_hal_viewer.cpp shows how to use Metavision HAL API for visualizing events stream.

Expected Output

The application visualizes CD events on the screen.

Expected Output from Metavision HAL Viewer Sample

How to start

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 the file from Metavision Dataset):


./metavision_hal_viewer -i spinner.raw


metavision_hal_viewer.exe -i spinner.raw

To check for additional options:


./metavision_hal_viewer -h


metavision_hal_viewer.exe -h

Code Overview

Visualization of Events

To apply processing on every received CD event, you need to register a callback on the decoder, as shown in the following code snippet:

    // Get the handler of CD events
    Metavision::I_EventDecoder<Metavision::EventCD> *i_tddecoder =

    if  (i_tddecoder) {
        // Register a lambda function to be called on every CD events
                    [&event_analyzer](const Metavision::EventCD *begin, const Metavision::EventCD *end) {
            event_analyzer.process_events(begin, end);

To set up the display frame, the sensor size can be retrieved as follows:

    Metavision::I_Geometry *i_geometry = device->get_facility<Metavision::I_Geometry>();
    if (!i_geometry) {
        std::cerr << "Could not retrieve geometry." << std::endl;
        return 4;

Then, the data needs to be streamed from the device to the decoder:

            // Here we polled data, so we can launch decoding
            long n_bytes;
            uint8_t *raw_data = i_eventsstream->get_latest_raw_data(n_bytes);

            // This will trigger callbacks set on decoders: in our case EventAnalyzer.process_events
            i_decoder->decode(raw_data, raw_data + n_bytes);

Accessing Triggers

You can access triggers using Metavision::I_TriggerIn and Metavision::I_TriggerOut classes.

This code snippet shows how to get the trigger facilities. Here, we activate the output trigger and enable the reading on the input trigger on the channel 6.

    // Enable internal trigger loopback for trigger testing purposes.
    // When enabling trigger out (pin 0/TRIGGER_OUT), the signal is also duplicated on trigger channel 6
    Metavision::I_TriggerOut *i_trigger_out = device->get_facility<Metavision::I_TriggerOut>();
    Metavision::I_TriggerIn *i_trigger_in   = device->get_facility<Metavision::I_TriggerIn>();
    if (i_trigger_in && i_trigger_out) {


The available channels for input triggers depend on the camera model. The list of available triggers for your camera model can be found in its datasheet.


For Prophesee’s cameras, the input trigger number 6 is a special trigger that creates a loopback for output triggers. When a signal is sent on the output trigger, it will be copied also to the input trigger number 6. This can be used as a debug tool to verify the output signal.

Recording a RAW File

The Metavision::I_EventsStream class provides a function Metavision::I_EventsStream::log_raw_data() to record all events received from the camera to a RAW file.

The following code snippet shows how to start data recording:

    Metavision::I_EventsStream *i_eventsstream = device->get_facility<Metavision::I_EventsStream>();
    if (i_eventsstream) {
        if (out_raw_file_path != "") {
    } else {
        std::cerr << "Could not initialize events stream." << std::endl;
        return 3;

To stop recording, the method Metavision::I_EventsStream::stop_log_raw_data() has to be called.