SDK UI Python bindings API

class metavision_sdk_ui.BaseWindow

Base class for displaying images and handling events in a window, deriving from BaseGLFWUI.

This class cannot directly be used as is, instead, one needs to instantiate one of its derived class (i.e. Window or MTWindow).

note

Each window has its own events queue that needs to be regularly processed, either explicitly by calling BaseWindow::poll_events or implicitly by calling Window::show or MTWindow::show_async with auto_poll = true (default behavior). Events are polled from the system and push to the windows’ internal queue by calling EventLoop::poll_and_dispatch.

warning

The constructor and destructor of this class must only be called from the main thread

get_rendering_mode(self: metavision_sdk_ui.BaseWindow) Metavision::BaseWindow::RenderMode

Gets the window’s color rendering mode.

return

The window’s color rendering mode (Either RenderMode::GRAY or RenderMode::BGR)

get_size(self: metavision_sdk_ui.BaseWindow) tuple

Returns the tuple (widh, height)

poll_events(self: metavision_sdk_ui.BaseWindow) None

Dequeues events in this window’s queue and calls corresponding callbacks.

note

Calling this method is not mandatory when Window::show and MTWindow::show_async are called with auto_poll = true (i.e. default behavior). However, when the image to display is somehow generated from input events (e.g. drawing ROIs from mouse inputs), then it might be useful to call this method before both generating the image and calling Window::show or MTWindow::show_async (with auto_poll = false) to reduce the latency between the moment when the events are generated and the moment when the image is actually displayed.

warning

The callbacks are called in the same thread as this method’s calling one. This means that if this method is called from a different thread than the one calling Window::show or MTWindow::show_async, a special care must be taken, in the callbacks, to avoid concurrency problems.

set_close_flag(self: metavision_sdk_ui.BaseWindow) None

Asks the window to close.

note

This only sets the window’s close flag to True but doesn’t actually close the window. The window will effectively be closed when the destructor is called.

set_cursor_pos_callback(self: metavision_sdk_ui.BaseWindow, arg0: object) None

Sets a callback that will be called when the mouse’s cursor moves on the current window.

cb

The callback to call on a mouse cursor event

note

See GLFW’s documentation (GLFWcursorposfun) for more information

set_keyboard_callback(self: metavision_sdk_ui.BaseWindow, arg0: object) None

Sets a callback that will be called when a key is pressed.

cb

The callback to call on a key event

warning

Due to a GLFW’s limitation, this callback returns key codes corresponding to the standard US keyboard layout. However, keys corresponding to unicode characters are mapped internally to match the current keyboard layout.

note

See GLFW’s documentation (GLFWkeyfun) for more information

set_mouse_callback(self: metavision_sdk_ui.BaseWindow, arg0: object) None

Sets a callback that will be called when a mouse’s button is pressed.

cb

The callback to call on a mouse event

note

See GLFW’s documentation (GLFWmousebuttonfun) for more information

should_close(self: metavision_sdk_ui.BaseWindow) bool

Indicates whether the window has been asked to close.

return

True if the window should close, False otherwise

note

This returns the window’s close flag

class metavision_sdk_ui.EventLoop(self: metavision_sdk_ui.EventLoop) None

A static class used to dispatch system events to the windows they belong to.

static poll_and_dispatch(sleep_time_ms: int = 0) None

Polls events from the system and pushes them into the corresponding windows’ internal queue.

sleep_time_ms

Amount of time in ms this call will wait after polling and dispatching the events

warning

Must only be called from the main thread

class metavision_sdk_ui.MTWindow(self: metavision_sdk_ui.MTWindow, title: str, width: int, height: int, mode: metavision_sdk_ui.BaseWindow.RenderMode, open_directly: bool = False) None

Window using its own rendering thread to render images.

Images are displayed at a fixed frequency (i.e. the screen’s refresh one) by the internal rendering thread.

warning

The constructor and destructor of this class must only be called from the main thread

destroy(self: metavision_sdk_ui.MTWindow) None

Destroys the window. This method has to be called after closing the window if this class has been constructed using open_directly=True.

show_async(self: metavision_sdk_ui.MTWindow, image: numpy.ndarray, auto_poll: bool = True) None

Asynchronously displays an image.

Here asynchronously means that the image is not immediately displayed, but will be done later on by the internal rendering thread. This window uses a front/back buffers mechanism to avoid copying images.

image

The image to display. The image is passed as a non constant reference in order to be swapped with the front buffer and thus avoid useless copies.

auto_poll

If True, events in this window’s queue are dequeued and processed. If false, BaseWindow::poll_events must explicitly be called.

warning

If auto_poll is True, the events are processed in this method’s calling thread, not in the internal rendering one.

class metavision_sdk_ui.Window(self: metavision_sdk_ui.Window, title: str, width: int, height: int, mode: metavision_sdk_ui.BaseWindow.RenderMode, open_directly: bool = False) None

A window that can be used to display images from any thread.

This window has no internal rendering thread, meaning that the images are displayed at the same frequency as the one of the Window::show method.

warning

The constructor and destructor of this class must only be called from the main thread

destroy(self: metavision_sdk_ui.Window) None

Destroys the window. This method has to be called after closing the window if this class has been constructed using open_directly=True.

show(self: metavision_sdk_ui.Window, image: numpy.ndarray, auto_poll: bool = True) None

Displays an image.

image

The image to display

auto_poll

If True, events in this window’s queue are dequeued and processed. If false, BaseWindow::poll_events must explicitly be called.

class metavision_sdk_ui.BaseWindow.RenderMode(self: metavision_sdk_ui.BaseWindow.RenderMode, value: int) None

Members:

GRAY

BGR