SDK Analytics Algorithms

class Metavision::CountingAlgorithm

Class to count objects using Metavision Counting API.

Public Types

using OutputCb = std::function<void(const OutputEvent&)>

Type of the callback to access the last count.

Public Functions

CountingAlgorithm(int width, int height, int cluster_ths, Metavision::timestamp accumulation_time_us = 1)

Constructor.

Parameters
  • width – Sensor’s width (in pixels)

  • height – Sensor’s height (in pixels)

  • cluster_ths – Minimum width (in pixels) below which clusters of events are considered as noise

  • accumulation_time_us – Accumulation time of the event buffer before processing (in us)

~CountingAlgorithm()

Default destructor.

void add_line_counter(int row)

Adds a new line to count objects.

Parameters

row – Specifies which row (y coordinate in pixels) is used to count

template<typename InputIt>
void process_events(InputIt it_begin, InputIt it_end)

Processes a buffer of events.

Template Parameters

InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

Parameters
  • it_begin – Iterator to the first input event

  • it_end – Iterator to the past-the-end event

void set_output_callback(const OutputCb &output_cb)

Function to pass a callback to get the last count.

Parameters

output_cb – Function to call

void reset_counters()

Resets the count of all lines.

template<typename T, typename V, V T::* v, typename precision_type = float>
class Metavision::DominantValueEventsAlgorithm

Class computing the dominant value of an event’s field from an events batch.

Template Parameters
  • T – Type for which the dominant value of one of its fields will be estimated

  • V – Type of the field from which the dominant value is extracted

  • v – Address in T of the field from which the dominant value is extracted

  • precision_type – Return type of the dominant value, used to define the type of the boundaries of the histogram bins

Public Functions

inline DominantValueEventsAlgorithm(precision_type min_val, precision_type max_val, precision_type precision_val, unsigned int min_count)

Constructor.

We split the range [ min_val, max_val ] to get values spaced by precision_val . Bins are centered around these values and are of a width that ensures that consecutive bins touch each other. For example, given the range [3, 5] and precision_val = 1, it will compute the bin centers {3, 4, 5}, the boundaries of which are given by {2.5, 3.5, 4.5, 5.5}

Note

The histogram bins are initialized during the class construction and won’t change dynamically.

Parameters
  • min_val – Minimum included value (lower bound of the histogram bins)

  • max_val – Maximum included value (upper bound of the histogram bins)

  • precision_val – Width of the bins of the histogram (same unit as the value to estimate)

  • min_count – Minimum size of a given bin in the histogram to be eligible as dominant

template<typename InputIt>
inline bool compute_dominant_value(InputIt begin, InputIt end, precision_type &output_dominant_value)

Computes the dominant value from a batch of events.

Template Parameters

InputIt – An iterator type over an event of type T

Parameters
  • begin – First iterator of the T events buffer to process

  • end – End iterator of the T events buffer to process

  • output_dominant_value – Peak of the histogram of the values contained between begin and end

Returns

false if none of the bins were sufficiently filled with respect to the count criterion

template<typename precision_type = float>
class Metavision::DominantValueMapAlgorithm

Class computing the dominant value of a map.

Template Parameters

precision_type – Return type of the dominant value, used to define the type of the boundaries of the histogram bins

Public Functions

DominantValueMapAlgorithm(precision_type min_val, precision_type max_val, precision_type precision_val, unsigned int min_count)

Constructor.

We split the range [ min_val, max_val ] to get values spaced apart by precision_val . Bins are centered around these values and are of width step so that consecutive bins touch each other. For example, given the range [3, 5] and precision_val = 1, it will compute the bin centers {3, 4, 5}, the boundaries of which are given by {2.5, 3.5, 4.5, 5.5}

Note

The histogram bins are initialized during the class construction and won’t change dynamically.

Parameters
  • min_val – Minimum included value (lower bound of the histogram bins)

  • max_val – Maximum included value (upper bound of the histogram bins)

  • precision_val – Width of the bins of the histogram (same unit as the value to estimate)

  • min_count – Minimum size of a given bin in the histogram to be eligible as dominant

~DominantValueMapAlgorithm() = default

Destructor.

bool compute_dominant_value(const cv::Mat &value_map, precision_type &output_dominant_value)

Computes the dominant value from a value map.

Parameters
  • value_map – Input map containing values

  • output_dominant_value – Peak of the histogram of the values contained in value_map

Returns

false if none of the bins were sufficiently filled with respect to the count criterion

class Metavision::FrequencyMapAsyncAlgorithm

Class that estimates the pixel-wise frequency of vibrating objects using Metavision Vibration API.

Public Types

using OutputCb = std::function<void(timestamp, OutputMap&)>

Type of the callback to access the period map.

Public Functions

FrequencyMapAsyncAlgorithm(int width, int height, const FrequencyEstimationConfig &frequency_config)

Builds a new FrequencyMapAsyncAlgorithm object.

Parameters
  • width – Sensor’s width in pixels

  • height – Sensor’s height in pixels

  • frequency_config – Frequency estimation configuration

~FrequencyMapAsyncAlgorithm()

Default destructor.

void set_output_callback(const OutputCb &output_cb)

Sets a callback to get the output frequency map.

Parameters

output_cb – Callback to call

void set_update_frequency(const float freq)

Sets the frequency at which the algorithm generates the frequency map.

Parameters

freq – Frequency at which the frequency map will be generated

template<typename InputIt>
void process_events(InputIt it_begin, InputIt it_end)

Processes a buffer of events.

Template Parameters

InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

Parameters
  • it_begin – Iterator to the first input event

  • it_end – Iterator to the past-the-end event

class Metavision::HeatMapFrameGeneratorAlgorithm

Class that produces a BGR image of a floating point value map.

A colormap bar at the bottom of the image shows the color convention. Pixels for which a value was not computed are shown in black. Also pixels outside the defined minimum/maximum values are shown in black too.

Public Types

using float_type = float

Type of floating point values.

Public Functions

HeatMapFrameGeneratorAlgorithm(float_type min_value, float_type max_value, float_type value_precision, int width, int height, const std::string &unit_str = std::string(), unsigned int cmap = cv::COLORMAP_JET, bool do_invert_cmap = true)

Constructor.

Parameters
  • min_value – Minimum value

  • max_value – Maximum value

  • value_precision – Precision used to determine the number of decimal digits to display (0.5, 0.01, …)

  • width – Sensor’s width (in pixels)

  • height – Sensor’s height (in pixels)

  • unit_str – String representation of the unit of measurement, e.g. Hz, us, m/s …

  • cmap – Colormap used to colorize the value map

  • do_invert_cmap – Flip the uchar values before applying the color map

~HeatMapFrameGeneratorAlgorithm()

Destructor.

void generate_bgr_heat_map(const cv::Mat_<float_type> &value_map, cv::Mat &out_image_bgr)

Draws the value map with a bar showing the colormap convention.

Parameters
  • value_map – Input value map, 1 floating point channel (CV_32FC1)

  • out_image_bgr – Output image

int get_full_width() const

Returns the full generated image’s width.

int get_full_height() const

Returns the full generated image’s height.

class Metavision::JetMonitoringAlgorithm : public Metavision::AsyncAlgorithm<JetMonitoringAlgorithm>

Class that detects, counts, and timestamps jets that are being dispensed.

The algorithm starts by splitting the Region Of Interest (ROI) provided by the user into three parts. On the one hand, the central ROI is used to detect jets by identifying peaks in the event-rate. On the other hand, the two surrounding ROIs are used to analyze the background activity.

Jet Monitoring results are provided through callbacks to which the user can subscribe. The first two provide the Jet Monitoring results:

  • JetCallback : when a jet is detected

  • AlarmCallback: when an alarm is raised

While the other two provide contextual information on the time slice that has just been processed:

  • SliceCallback: detailed information about the time slice (See JetMonitoringSliceData)

  • AsyncCallback: end-timestamp and number of events of the time slice

Public Types

enum ROI

Enum listing ROIs for counting and background activity.

Values:

enumerator DETECTION
enumerator BG_NOISE_1
enumerator BG_NOISE_2
enumerator TOTAL
using JetCallback = std::function<void(const EventJet&)>

Type of callback called when a jet is detected (Main interface)

using AlarmCallback = JetMonitoringAlarms::AlarmCallback

Type of callback called when an alarm is raised (Main interface)

using SliceCallback = std::function<void(const JetMonitoringSliceData&)>

Type of callback called at the end of each time slice processing, with detailed information about the internal state. It is mainly intended for diagnostic/debugging.

using AsyncCallback = std::function<void(const timestamp, const size_t)>

Type of callback called at the end of each time slice processing, with the timestamp and the number of events.

In case the SliceCallback has also been specified, the AsyncCallback will be called last

Public Functions

JetMonitoringAlgorithm(const JetMonitoringAlgorithmConfig &algo_config, const JetMonitoringAlarmConfig &alarm_config = JetMonitoringAlarmConfig())

Constructor.

Parameters
  • algo_config – Jet monitoring parameters

  • alarm_config – Jet monitoring alarm parameters

void reset_state()

Resets internal state.

void set_on_jet_callback(const JetCallback &cb)

Sets the callback that is called when a jet is detected.

Parameters

cb – Callback processing a const reference of EventJet

void set_on_alarm_callback(const AlarmCallback &cb)

Sets the callback that is called when an alarm is raised.

Parameters

cb – Callback processing a const reference of EventJetAlarm

void set_on_slice_callback(const SliceCallback &cb)

Sets the callback that is called at the end of each slice to provide JetMonitoring-related data.

Parameters

cb – Callback processing a const reference of JetMonitoringSliceData

void set_on_async_callback(const AsyncCallback &cb)

Sets the callback that is called at the end of each slice to provide AsyncAlgorithm-related data.

Parameters

cb – Callback processing the time slice duration and the number of events processsed during time slice

template<typename T, typename F, F T::* f>
class Metavision::MapGeneratorAsyncAlgorithm : public Metavision::AsyncAlgorithm<MapGeneratorAsyncAlgorithm<T, F, f>>

Class that accumulates events in a map.

More specifically, this class accumulates one of the event’s fields in a map. Each map’s cell contains the last value of that field at that location. Under the hood this class uses the OpenCV’s Mat_<T> structure, meaning that it is only compatible with the types for which the Mat_<T> structure is compatible too (i.e. uchar, short, ushort, int, float and double). This class is not compatible with OpenCV’s vector types (i.e. instantiations of the Vec<T, int cn> class).

Template Parameters
  • T – Type, one of the fields of which will be accumulated in the map

  • F – Type of the field that will be accumulated in the map

  • f – Address in T of the field to be accumulated

Public Functions

MapGeneratorAsyncAlgorithm(int width, int height)

Builds a new MapGeneratorAsyncAlgorithm object.

Parameters
  • width – Sensor’s width (in pixels)

  • height – Sensor’s height (in pixels)

~MapGeneratorAsyncAlgorithm() = default

Default destructor.

void set_output_callback(const OutputCb &cb)

Sets the callback that will be called to let the user retrieve the generated map.

The generated map will be passed through the callback via a non constant reference, meaning that the client is free to copy it or swap it.

Note

In case of a swap with a non initialized map, it will automatically be initialized by the MapGeneratorAsyncAlgorithm.

Parameters

cb – The callback to call

class Metavision::PeriodMapAsyncAlgorithm

Class that estimates the pixel-wise period of vibrating objects using Metavision Vibration API.

Public Types

using OutputCb = std::function<void(timestamp, OutputMap&)>

Type of the callback to access the period map.

Public Functions

PeriodMapAsyncAlgorithm(int width, int height, const PeriodEstimationConfig &period_map_async_config)

Builds a new PeriodMapAsyncAlgorithm object.

Parameters
  • width – Sensor’s width (in pixels)

  • height – Sensor’s height (in pixels)

  • period_map_async_config – Period estimation configuration

~PeriodMapAsyncAlgorithm()

Default destructor.

void set_output_callback(const OutputCb &output_cb)

Sets a callback to get the output period map.

Parameters

output_cb – Callback to call

void set_update_frequency(const float freq)

Sets the frequency at which the algorithm generates the period map.

Parameters

freq – Frequency at which the period map will be generated

template<typename InputIt>
void process_events(InputIt it_begin, InputIt it_end)

Processes a buffer of events.

Template Parameters

InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

Parameters
  • it_begin – Iterator to the first input event

  • it_end – Iterator to the past-the-end event

class Metavision::PsmAlgorithm

Class that both counts objects and estimates their size using Metavision Particle Size Measurement API.

Public Functions

PsmAlgorithm(int sensor_width, int sensor_height, const std::vector<int> &rows, const LineClusterTrackingConfig &detection_config, const LineParticleTrackingConfig &tracking_config)

Constructor.

Parameters
  • sensor_width – Sensor’s width (in pixels)

  • sensor_height – Sensor’s height (in pixels)

  • rows – Rows on which to instantiate line cluster trackers

  • detection_config – Detection config

  • tracking_config – Tracking config

~PsmAlgorithm()

Destructor.

template<typename InputIt>
void process_events(InputIt it_begin, InputIt it_end)

Processes a buffer of events.

Template Parameters

InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

Parameters
  • it_begin – Iterator to the first input event

  • it_end – Iterator to the past-the-end event

template<typename InputIt>
void process_events(InputIt it_begin, InputIt it_end, const timestamp ts, LineParticleTrackingOutput &tracks, LineClustersOutput &line_clusters)

Processes a buffer of events and retrieves the detected particles in one call.

Template Parameters

InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

Parameters
  • it_begin[in] Iterator to the first input event

  • it_end[in] Iterator to the past-the-end event

  • ts[in] Upper bound timestamp of the events time slice

  • tracks[out] Detected particles for each line

  • line_clusters[out] Detected clusters for each line

void get_results(const timestamp ts, LineParticleTrackingOutput &tracks, LineClustersOutput &line_clusters)

Retrieves the detected particles since the last call to this method.

Parameters
  • ts[in] Upper bound timestamp of the processed events

  • tracks[out] Detected particles for each line

  • line_clusters[out] Detected clusters for each line

void reset()

Resets line cluster trackers and line particle trackers.

class Metavision::SpatterTrackerAlgorithm

Class that tracks spatter clusters using Metavision SpatterTracking API.

Public Types

using TrackerCb = std::function<void(const timestamp, const std::vector<EventSpatterCluster>&)>

Type of the callback to access the output cluster events.

Public Functions

SpatterTrackerAlgorithm(int width, int height, const SpatterTrackerAlgorithmConfig &config)

Builds a new SpatterTrackerAlgorithm object.

Parameters
  • width – Sensor’s width (in pixels)

  • height – Sensor’s height (in pixels)

  • config – Spatter tracker’s configuration

~SpatterTrackerAlgorithm()

Default destructor.

void set_output_callback(const TrackerCb &tracker_cb)

Registers a callback to get the output cluster events.

Parameters

tracker_cb – Function to call

void add_nozone(const cv::Point &center, int radius, bool inside = true)

Adds a region that isn’t used for tracking.

Parameters
  • center – Center of the region

  • radius – Radius of the region

  • inside – True if the region to filter is inside the defined shape, false otherwise

int get_cluster_count() const

Returns the current number of clusters.

Returns

The current number of clusters

template<typename InputIt>
void process_events(InputIt it_begin, InputIt it_end)

Processes a buffer of events.

Template Parameters

InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

Parameters
  • it_begin – Iterator to the first input event

  • it_end – Iterator to the past-the-end event

class Metavision::TrackingAlgorithm

Class that tracks objects using Metavision Tracking API.

Public Functions

TrackingAlgorithm(int sensor_width, int sensor_height, TrackingConfig &config)

Builds a new TrackingAlgorithm object.

Parameters
  • sensor_width – Sensor’s width.

  • sensor_height – Sensor’s height.

  • config – Tracking’s configuration.

~TrackingAlgorithm()

Default Destructor.

std::uint16_t get_min_size() const

Gets the size of the smallest trackable object.

std::uint16_t get_max_size() const

Gets the size of the biggest trackable object.

float get_min_speed() const

Gets the speed of the slowest trackable object.

float get_max_speed() const

Gets the speed of the fastest trackable object.

void set_min_size(std::uint16_t min_size)

Sets the size of the smallest trackable object.

Parameters

min_size – Size of the smallest object (in pixels)

void set_max_size(std::uint16_t max_size)

Sets the size of the biggest trackable object.

Parameters

max_size – Size of the biggest object (in pixels)

void set_min_speed(float min_speed)

Sets the speed of the slowest trackable object.

Parameters

min_speed – Speed of the slowest object

void set_max_speed(float max_speed)

Sets the speed of the fastest trackable object.

Parameters

max_speed – Speed of the fastest object

template<typename InputIt, typename OutputIt>
void process_events(InputIt it_begin, InputIt it_end, OutputIt output)

Processes a buffer of events.

Template Parameters
  • InputIt – Read-Only input event iterator type. Works for iterators over buffers of EventCD or equivalent

  • OutputIt – Output event iterator type. Works for iterators overs buffers of EventTrackingData

Parameters
  • it_begin[in] Iterator to the first input event

  • it_end[in] Iterator to the past-the-end event

  • output[out] Iterator to the output buffer