draw.tag

Description

Draws a tag (from obj_attrs) above each bounding box.

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

Draws a tag above each bounding box in the image, using information from selected attributes in obj_attrs. In the general example below, obj_attrs has 2 attributes (<attr a> and <attr b>). There are n detected bounding boxes, and each attribute has n corresponding tags stored in a list. The show config described subsequently is used to choose the attribute or attributes to be drawn.

{"obj_attrs": {<attr a>: [<tag 1>, ..., <tag n>], <attr b>: [<tag 1>, ..., <tag n>]}}

The following type conventions need to be observed:

  • Each attribute must be of type List, e.g., <attr a>: [<tag 1>, ..., <tag n>]

  • Each tag must be of type str, int, float, or bool to be convertable into str type for drawing

In the example below, obj_attrs has 3 attributes (“ids”, “gender” and “age”), where the last 2 attributes are nested within “details”. There are 2 detected bounding boxes, and thus each attribute consists of a list with 2 tags.

# Example
{"obj_attrs": {"ids":[1,2], "details": {"gender": ["female","male"], "age": [52,17]}}

The table below illustrates how show can be configured to achieve different outcomes for this example. Key takeaways are:

  • To draw nested attributes, include all the keys leading to them (within the obj_attrs dictionary), separating each key with a ->.

  • To draw multiple comma-separated attributes above each bounding box, add them to the list of show config.

No.

show config

Tag above 1st bounding box

Tag above 2nd bounding box

[“ids”]

“1”

“2”

[“details -> gender”]

“female”

“male”

[“details -> age”, “details -> gender”]

“52, female”

“17, male”

Inputs

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

bboxes (numpy.ndarray): A NumPy array of shape \((N, 4)\) containing normalized bounding box coordinates of \(N\) detected objects. Each bounding box is represented as \((x_1, y_1, x_2, y_2)\) where \((x_1, y_1)\) is the top-left corner and \((x_2, y_2)\) is the bottom-right corner. The order corresponds to bbox_labels and bbox_scores.

obj_attrs (Dict[str, Any]): A dictionary of attributes associated with each bounding box, in the same order as bboxes. Different nodes that produce this obj_attrs output type may contribute different attributes.

Outputs

none: No outputs produced.

Configs
  • show (List[str]) – default = [].
    List of desired attributes to be drawn. For more details on how to use this config, see the section above.

  • tag_color (List[int]) – default = [77, 103, 255].
    Define the color of the drawn tag, in BGR format. Defined values have to be integers, and \(0 \leq value \leq 255\).

Changed in version 1.2.0: draw.tag used to take in obj_tags (List[str]) as an input data type, which has been deprecated and now subsumed under obj_attrs, giving this node more flexibility. Also, the tag_color config is added to provide the option of changing the tag’s color.