async2v.components.pygame.display module

Summary

Classes:

AuxiliaryDisplay Abstract auxiliary display sub-component
AuxiliaryDisplayConfig Configuration for the AuxiliaryDisplay component
AuxiliaryDisplayConfigurator Configuration for the AuxiliaryDisplay component
AuxiliaryOpenCvDisplay Draw OpenCV frames to the auxiliary display surface.
Display Abstract pygame display
OpenCvDebugDisplay Zero configuration pygame debug display
OpenCvDisplay Pygame display drawing OpenCV frames
OpenCvMultiDisplay Pygame display drawing OpenCV frames from multiple sources

Reference

class Display

Bases: async2v.components.base.SubComponent

Abstract pygame display

The pygame MainWindow supports multiple displays. The currently selected display is rendered on the main display area. An optional AuxiliaryDisplay can be rendered next to the main display area.

draw(surface)

This method needs to overridden to draw the content of the display to the given surface.

Parameters:surface (Surface) – Pygame surface that can be used completely to draw the content of this display
Return type:List[MouseRegion]
Returns:List of mouse regions relative to the given surface. For those regions, mouse events will be emitted by the containing MainWindow. See mouse for details.
class AuxiliaryDisplayConfig(resolution)

Bases: object

Configuration for the AuxiliaryDisplay component

resolution = None
Type:Tuple[int, int]

Resolution (width, height)

class AuxiliaryDisplayConfigurator

Bases: async2v.cli.Configurator

Configuration for the AuxiliaryDisplay component

static config_from_args(args)

Get configuration from argparse output

class AuxiliaryDisplay(config)

Bases: async2v.components.base.SubComponent

Abstract auxiliary display sub-component

This pygame-based auxiliary display can be added the pygame MainWindow. It will be rendered next to the main display on the right. In fullscreen mode, the main window then spans the whole virtual display. The physical displays need to be configured accordingly. For this to work, the auxiliary display needs to be provided the resolution of the physical auxliary display. The resolution of the main display can then be determined automatically, as it takes the remaining space of the virtual display.

+-----------------+-------------+
|                 |             |
|                 | aux display |
|     main        |             |
|     display     +-------------+
|                 |
|                 |
+-----------------+
Parameters:config (AuxiliaryDisplayConfig) – Can be generated via AuxiliaryDisplayConfigurator
static configurator()

Convenience method to create a matching configurator

Return type:AuxiliaryDisplayConfigurator
resolution

Resolution (width, height) of auxiliary display

Return type:Tuple[int, int]
draw(surface)

This method needs to overridden to draw the content of the display to the given surface.

Parameters:surface (Surface) –
Return type:None
class AuxiliaryOpenCvDisplay(config, source)

Bases: async2v.components.pygame.display.AuxiliaryDisplay

Draw OpenCV frames to the auxiliary display surface.

See AuxiliaryDisplay for more information.

Frames are scaled without preserving the aspect ratio. This makes it easy to draw on the whole available surface without knowing the target aspect ratio.

Parameters:config (AuxiliaryDisplayConfig) – Can be generated via AuxiliaryDisplayConfigurator
class OpenCvDisplay(source)

Bases: async2v.components.pygame.display.Display

Pygame display drawing OpenCV frames

Scales OpenCV frames preserving the aspect ratio and draws them on the given surface.

This display returns a MouseRegion overlaying the displayed frame with the input frame source as name and the size of the input frame as original_size.

Parameters:source – Key of input event. Needs to provide Frame events.
class OpenCvMultiDisplay

Bases: async2v.components.pygame.display.Display

Pygame display drawing OpenCV frames from multiple sources

Scales OpenCV frames preserving the aspect ratio and draws them into a tiled layout. If the number of tiles changes, if the screen size changes or at latest after 60 seconds, the layout is reevaluated and optimized for the best (largest) tile size. All tiles within a layout have the same size.

For each tile, this display returns a MouseRegion overlaying the displayed frame with the input frame source as name and the size of the input frame as original_size.

frames

Override this property to return a list of OpenCV frames to be rendered.

This list should be stable during one iteration (e.g. directly calculated from the input fields).

Return type:List[Frame]
after_draw_frame(frame_index, frame, surface, frame_surface)

Override to draw extra information on a single frame

Parameters:
  • frame_index (int) – Index of the frame in the list returned by frames
  • frame (Frame) – Frame that has been rendered
  • surface (Surface) – pygame.Surface of the whole display
  • frame_surface (Surface) – pygame.Surface the frame has been rendered to
Return type:

None

after_draw(surface)

Override to draw extra information on the whole display

Parameters:surface (Surface) – pygame.Surface of the whole display
Return type:None
class OpenCvDebugDisplay

Bases: async2v.components.pygame.display.OpenCvMultiDisplay

Zero configuration pygame debug display

Renders the latest frames pushed to the key OPENCV_FRAME_EVENT by frame source: For each source, a separate tile is created. The builtin VideoSource automatically pushes to the debug event key.

For each tile, this display returns a MouseRegion overlaying the displayed frame with the input frame source as name and the size of the input frame as original_size.