draw.legend

Description

Displays selected information from preceding nodes in a legend box.

class Node(config=None, **kwargs)[source]

Draws a translucent legend box on a corner of the image, containing selected information produced by preceding nodes in the format <data type>: <value>. Supports in-built PeekingDuck data types defined in Glossary as well as custom data types produced by custom nodes.

This example screenshot shows fps from dabble.fps, count from dabble.bbox_count and cum_avg from dabble.statistics displayed within the legend box.

../_images/legend.png


With the exception of the zone_count data type from dabble.zone_count, all other selected in-built PeekingDuck data types or custom data types must be of types int, float, or str. Note that values of float type such as fps and cum_avg are displayed in 2 decimal places.

Inputs

all (Any): This data type contains all the outputs from preceding nodes, granting a large degree of flexibility to nodes that receive it. Examples of such nodes include draw.legend, dabble.statistics, and output.csv_writer.

Outputs

img (numpy.ndarray): A NumPy array of shape \((height, width, channels)\) containing the image data in BGR format.

Configs
  • box_opacity (float) – default = 0.3.
    Opacity of legend box background. A value of 0.0 causes the legend box background to be fully transparent, while a value of 1.0 causes it to be fully opaque.

  • font (Dict[str, Union[float, int]]) – default = {size: 0.7, thickness: 2}.
    Size and thickness of font within legend box. Examples of visually acceptable options are:
    720p video: {size: 0.7, thickness: 2}
    1080p video: {size: 1.0, thickness: 3}

  • position (str) – {“top”, “bottom”}, default = “bottom”.
    Position to draw legend box. “top” draws it at the top-left position while “bottom” draws it at bottom-left.

  • show (List[str]) – default = [].
    Include in this list the desired data type(s) to be drawn within the legend box, such as ["fps", "count", "cum_avg"] in the example screenshot. Custom data types produced by custom nodes are also supported. If no data types are included, an error will be produced.

Changed in version 1.2.0: Merged previous all_legend_items and include configs into a single show config for greater clarity. Added support for drawing custom data types produced by custom nodes, to improve the flexibility of this node.