SDK Core Utils

class Metavision::CDFrameGenerator

Utility class to display CD events.

Public Functions

CDFrameGenerator(long width, long height, bool process_all_frames = false)

Default constructor.

Parameters
  • width: Width of the image (in pixels)

  • height: Height of the image (in pixels)

  • process_all_frames: If true, it will process all frames, not just the latest one. Note that if true it can slow down the process.

~CDFrameGenerator()

Destructor.

void set_colors(const cv::Scalar &background_color, const cv::Scalar &on_color, const cv::Scalar &off_color, bool colored = false)

Sets the color used to generate the frame.

By default, the frame generated will be 8 bits single channel with the default colors grey, white, black as background, on and off colors respectively. If the parameter colored is false, then the generated frame will be 8 bits single channel and the first channel will be used to define each colors (i.e. the other channels will be ignored). If the parameter colored is true, then the generated frame will be 8 bits three channels.

Parameters
  • background_color: Color used as background, when no events were received for a pixel, default: grey cv::Scalar::all(128)

  • on_color: Color used for on events, default: white cv::Scalar::all(255)

  • off_color: Color used for off events, default: black cv:Scalar::all(0)

  • colored: If the generated frame should be single or three channels

void add_events(const Metavision::EventCD *begin, const Metavision::EventCD *end)

Adds the buffer of events to be displayed.

Parameters
  • begin: Beginning of the buffer of events

  • end: End of the buffer of events

void set_display_accumulation_time_us(timestamp display_accumulation_time_us)

Sets the time interval to display events.

The events shown at each refresh are such that their timestamps are in the last ‘display_accumulation_time_us’ microseconds from the last received event timestamp.

Parameters
  • display_accumulation_time_us: The time interval to display events from up to now (in us).

bool start(std::uint16_t fps, const std::function<void(const timestamp&, const cv::Mat&)> &cb)

Starts the generator thread.

Return

true if the thread started successfully, false otherwise. Also returns false, if the thread is already started.

Parameters
  • fps: Frame rate

  • cb: Function to call every time a new frame is available. It takes in input the time (in us) of the new frame and the frame. The frame passed as a parameter is guaranteed to be available and left untouched until the next time the callback is called. This means that you don’t need to make a deep copy of it, if you only intend to use the frame until the next one is made available by the callback.

bool stop()

Stops the generator thread.

Return

true if the thread has been stopped successfully, false otherwise. Return false if the thread had not been previously started

struct Metavision::RGBColor

Struct that represents a color in RGB colorspace.

Public Members

double r

a fraction between 0 and 1

double g

a fraction between 0 and 1

double b

a fraction between 0 and 1

struct Metavision::HSVColor

Struct that represents a color in HSV colorspace.

Public Members

double h

angle in degrees

double s

a fraction between 0 and 1

double v

a fraction between 0 and 1

RGBColor Metavision::hsv2rgb(HSVColor hsv)

Utility function to convert from HSV to RGB colorspace.

Return

RGBColor the color converted in RGB colorspace

Parameters
  • hsv: A color in HSV colorspace

HSVColor Metavision::rgb2hsv(RGBColor rgb)

Utility function to convert from RGB to HSV colorspace.

Return

HSVColor the color converted in HSV colorspace

Parameters
  • rgb: A color in RBB colorspace

enum Metavision::ColorPalette

Enum class representing available color palettes.

Values:

enumerator Light
enumerator Dark
enumerator Gray
enum Metavision::ColorType

Enum class representing one of the possible type of colors.

Values:

enumerator Background
enumerator Positive
enumerator Negative
enumerator Auxiliary
const RGBColor &Metavision::getColor(const ColorPalette &palette, const ColorType &type)

Gets a color given a palette and the color type.

Return

The color associated to the given palette and type

Parameters
  • palette: The requested color palette

  • type: The requested color type

const RGBColor &Metavision::getColor(const ColorPalette &palette, const std::string &name)

Gets a color given a palette and the color name.

Return

The color associated to the given palette and name

Parameters
  • palette: The requested color palette

  • name: The requested color name

class Metavision::FrameComposer

This class implements an object capable of displaying a big image containing many images in an openGL window.

You need to first call method FrameComposer::add_new_subimage_parameters for each small image that you want to display in the big one. It will create an ImageParams object that will store the reference to the small image but also its position and other fields. Every time you call FrameComposer::update_subimage, FrameComposer will gather all ImageParams, put image at the right place in the big one and copy that in the output image.

Ideally the class takes integer pixels as inputs (CV_8UC1 or CV_8UC3). In case of floating point values, the cv::Mat is converted to an int type, which might slightly slow down the process.

Public Functions

FrameComposer(const cv::Vec3b &background_color = cv::Vec3b(0, 0, 0))

Constructor.

Parameters
  • background_color: Default color of the composition background (CV_8UC3)

unsigned int add_new_subimage_parameters(int top_left_x, int top_left_y, const ResizingOptions &resize_options, const GrayToColorOptions &gray_to_color_options)

Selects a sub-part of the final composed image and defines its preprocessing options.

Return

Reference (integer) of the sub-image to update later with update_subimage

Parameters
  • top_left_x: X-position of the top-left corner of the image in the composition

  • top_left_y: Y-position of the top-left corner of the image in the composition

  • resize_options: Options used to resize the image

  • gray_to_color_options: Options used to rescale and/or apply a colormap on the grayscale image

bool update_subimage(unsigned int img_ref, const cv::Mat &image)

Update the sub-part of the final image corresponding to the reference img_ref.

Parameters
  • img_ref: Reference ID of the sub-image, defined in the function add_new_subimage_parameters

  • image: Image to display at the corresponding location in the full composed image If the type is different than CV_8UC3 or CV_8UC1, then a conversion is performed

const int get_total_width() const

Returns the width of the output image.

const int get_total_height() const

Returns the height of the output image.

struct GrayToColorOptions

Settings used to rescale and/or apply a colormap on a grayscale image.

Public Members

unsigned char min_rescaling_value = 0

Min grayscale value for the rescaling.

unsigned char max_rescaling_value = 255

Max grayscale value for the rescaling.

int color_map_id = -1

Colormap to apply:

  • None = -1

  • COLORMAP_AUTUMN = 0

  • COLORMAP_BONE = 1

  • COLORMAP_JET = 2

  • COLORMAP_WINTER = 3

  • COLORMAP_RAINBOW = 4

  • COLORMAP_OCEAN = 5

  • COLORMAP_SUMMER = 6

  • COLORMAP_SPRING = 7

  • COLORMAP_COOL = 8

  • COLORMAP_HSV = 9

  • COLORMAP_PINK = 10

  • COLORMAP_HOT = 11

struct ResizingOptions

Settings used to resize or crop an image.

Public Members

const unsigned int height

New size of the image in the final composition.

const bool enable_crop

Whether to enable cropping the image to the specified width and height (maintains the center)

const InterpolationType interp_type

Type of interpolation used to resize images.

template<typename timestamp_type>
class Metavision::TMostRecentTimestampBuffer

Class representing a buffer of the most recent timestamps observed at each pixel of the camera.

Note

The interface follows the one of cv::Mat

Public Functions

TMostRecentTimestampBuffer()

Default constructor.

TMostRecentTimestampBuffer(int rows, int cols, int channels = 1)

Initialization constructor.

TMostRecentTimestampBuffer(const TMostRecentTimestampBuffer<timestamp_type> &other)

Copy constructor.

~TMostRecentTimestampBuffer()

Destructor.

void create(int rows, int cols, int channels = 1)

Allocates the buffer.

void release()

Deallocates the buffer.

int rows() const

Accesses the number of rows of the buffer.

int cols() const

Accesses the number of columns of the buffer.

cv::Size size() const

Accesses the size of the buffer.

int channels() const

Accesses the number of channels of the buffer.

bool empty() const

Checks whether the buffer is empty.

void set_to(timestamp_type ts)

Sets all elements of the timestamp buffer to a constant.

void copy_to(TMostRecentTimestampBuffer<timestamp_type> &other) const

Copies this timestamp buffer into the specified one.

void swap(TMostRecentTimestampBuffer<timestamp_type> &other)

Swaps the timestamp buffer with the specified one.

const timestamp_type &at(int y, int x, int c = 0) const

Retrieves the reference of the timestamp at the specified pixel.

timestamp_type &at(int y, int x, int c = 0)

Retrieves the reference of the timestamp at the specified pixel.

const timestamp_type *ptr(int y = 0, int x = 0, int c = 0) const

Retrieves the pointer to the timestamp at the specified pixel.

timestamp_type *ptr(int y = 0, int x = 0, int c = 0)

Retrieves the pointer to the timestamp at the specified pixel.

timestamp_type max_across_channels_at(int y, int x) const

Retrieves the maximum timestamp across channels at the specified pixel.

cv::Mat generate_img_time_surface(timestamp_type last_ts, timestamp_type delta_t) const

Generates a CV_8UC1 image of the time surface for the 2 channels Side-by-side: negative polarity time surface, positive polarity time surface The time surface is normalized between last_ts (0) and last_ts - delta_t (255)

cv::Mat generate_img_time_surface_collapsing_channels(timestamp_type last_ts, timestamp_type delta_t) const

Generates a CV_8UC1 image of the time surface, merging the 2 channels The time surface is normalized between last_ts (0) and last_ts - delta_t (255)

template<class T, bool acquire_shared_ptr = false, bool bounded_memory = false>
class Metavision::ObjectPool

Class that creates a reusable pool of heap allocated objects.

The ObjectPool allocates objects that are returned to the pool upon destruction. acquire is used to allocate or re-use a previously allocated object instance. The object are made available through a std::unique_ptr or a std::shared_ptr according to the template acquire_shared_ptr. The smart pointers are given a custom deleter, which automatically adds the object back to the pool upon destruction.

Template Parameters
  • T: the type of object stored

  • acquire_shared_ptr: if true, the object are wrapped by a std::shared_ptr, otherwise a std::unique_ptr is returned instead

Public Functions

template<typename ...Args>
ObjectPool(size_t num_initial_objects = 64, Args&&... args)

Constructor.

ObjectPool(const ObjectPool&) = delete

Copy constructor is deleted.

ObjectPool can not be copied

ObjectPool &operator=(const ObjectPool&) = delete

Copy assignment is deleted.

ObjectPool can not be copied

ObjectPool(ObjectPool &&pool)

Move Constructor.

Parameters
  • pool: The moved ObjectPool

ObjectPool &operator=(ObjectPool &&pool)

Moves assignment.

Return

The newly moved ObjectPool

Parameters
  • pool: The moved ObjectPool

void add(std::unique_ptr<T> t)

Adds an object to the pool.

Parameters
  • t: A unique_ptr storing the object

template<typename ...Args>
ptr_type acquire(Args&&... args)

Allocates or re-use a previously allocated object.

Return

A unique or shared pointer to the allocated object

Parameters
  • args: Optional arguments to be passed when allocating the object

bool empty() const

Checks if the pool is empty.

Return

true if the pool is empty, false if the pool contains object ready to be re-used

size_t size() const

Gets the number of objects in the pool.

Return

The number of previously allocated and ready to-reuse objects in the pool

template<typename T>
using Metavision::SharedObjectPool = ObjectPool<T, true, false>

Convenience alias to use a (memory unbounded) ObjectPool returning shared pointers.

Template Parameters
  • T: the type of object stored in the pool

template<typename T>
using Metavision::BoundedSharedObjectPool = ObjectPool<T, true, true>

Convenience alias to use a (memory bounded) ObjectPool returning shared pointers.

Template Parameters
  • T: the type of object stored in the pool

class Metavision::SimpleDisplayer

Class representing a simple displayer.

Public Functions

SimpleDisplayer(const std::string window_name, int fps = 50)

Constructor.

Parameters
  • window_name: Name of the window to display

  • fps: Frames per second to display

void stop()

Quits the display.

void swap_frame(cv::Mat &frame)

Updates the current frame by swap.

Parameters
  • frame: Frame to swap

void copy_frame(const cv::Mat &frame)

Updates the current frame by copy.

Parameters
  • frame: Frame to copy

void set_on_key_pressed_cb(const OnKeyPressedCb &on_key_pressed_cb)

Sets the callback that is called when a key is pressed.

Parameters
  • on_key_pressed_cb: Function to call

void run()

Runs the displayer. Should be called in the main thread.