Visualization package

Submodules

Visualization.DataModelVisualizer module

class Visualization.DataModelVisualizer.DataModelVisualizer(config: dict = {})[source]

Bases: object

Class to visualize the data models.

Create a data model visualizer object.

Parameters:

config (dict) – Configuration dict with the optional visualization parameters.

visualize_data_models(image: ndarray, data_models: List[BaseModel] | BaseModel, config: dict | None = None) ndarray[source]

Visualize a single or a list of data models.

Parameters:
  • image (np.ndarray) – Image where draw the data models.

  • data_models (Union[List[DataModels.BaseModel], DataModels.BaseModel]) – A single or a list of any data model.

  • config (Optional[dict]) – Optional configuration dict that will override the base config. Defaults to None.

Returns:

A copy of the original image with the data drawn.

Return type:

np.ndarray

Visualization.Defaults module

class Visualization.Defaults.Defaults[source]

Bases: object

COCO_KEYPOINTS_COLORS = {'left_ankle': (31, 0, 255), 'left_ear': (255, 0, 255), 'left_elbow': (159, 0, 255), 'left_eye': (223, 0, 255), 'left_hip': (95, 0, 255), 'left_knee': (63, 0, 255), 'left_shoulder': (191, 0, 255), 'left_wrist': (127, 0, 255), 'nose': (255, 255, 255), 'right_ankle': (31, 255, 0), 'right_ear': (255, 255, 0), 'right_elbow': (159, 255, 0), 'right_eye': (223, 255, 0), 'right_hip': (95, 255, 0), 'right_knee': (63, 255, 0), 'right_shoulder': (191, 255, 0), 'right_wrist': (127, 255, 0)}
COCO_KEYPOINTS_CONNECTION_RULES = [('left_ear', 'left_eye', (239, 0, 255)), ('right_ear', 'right_eye', (239, 235, 0)), ('left_eye', 'nose', (255, 0, 255)), ('nose', 'right_eye', (255, 255, 0)), ('left_shoulder', 'right_shoulder', (191, 255, 255)), ('left_shoulder', 'left_elbow', (175, 0, 255)), ('right_shoulder', 'right_elbow', (175, 255, 0)), ('left_elbow', 'left_wrist', (143, 0, 255)), ('right_elbow', 'right_wrist', (143, 255, 0)), ('left_hip', 'right_hip', (95, 255, 255)), ('left_hip', 'left_knee', (63, 0, 255)), ('right_hip', 'right_knee', (63, 255, 0)), ('left_knee', 'left_ankle', (47, 0, 255)), ('right_knee', 'right_ankle', (47, 255, 0)), ('left_shoulder', 'left_hip', (143, 0, 255)), ('right_shoulder', 'right_hip', (143, 255, 0)), ('nose', 'left_shoulder', (223, 0, 255)), ('nose', 'right_shoulder', (223, 255, 0))]
box_color = (224, 56, 84)
box_text_position = 'TOP_LEFT'
box_thickness = 2
static dict() dict[source]

Return the default attributes as a dict.

face_show_age = True
face_show_conf = True
face_show_emotion = True
face_show_emotion_conf = True
face_show_gender = True
face_show_gender_conf = True
face_show_recognized_dist = True
face_show_recognized_person = True
image_height = None
image_width = None
kp_color = (0, 0, 255)
kp_color_by_label = True
kp_line_thickness = 3
kp_radius = 5
kp_show_box = True
kp_show_conf = True
kp_show_connections = True
kp_show_detection_conf = True
kp_show_kp = True
kp_show_name = False
mask_alpha = 0.75
mask_color = (21, 57, 255)
mask_color_by_label = True
mask_colors_list = None
mask_show_box = True
mask_show_conf = True
mask_show_label = True
text_background = True
text_bg_alpha = 0.75
text_bg_color = (224, 56, 84)
text_color = (255, 255, 255)
text_direction = 'BOTTOM_RIGHT'
text_line_space = 15
text_scale = 1
text_thickness = 1

Visualization.DrawFace module

Visualization.DrawFace.draw(image: ndarray, data_models: List[Face] | Face, config: dict) ndarray[source]

Draw data form one or more Face data models on an image.

Parameters:
  • image (np.ndarray) – The image where draw the data.

  • data_models (Union[List[DataModels.Face], DataModels.Face]) – A list or a single Face data model.

  • config (dict) – A configuration dict.

Returns:

The input image with the data models drawn.

Return type:

np.ndarray

Visualization.DrawInstanceSegmentation module

Visualization.DrawInstanceSegmentation.draw(image: ndarray, data_models: List[InstanceSegmentation] | InstanceSegmentation, config: dict) ndarray[source]

Draw data from one or more InstanceSegmentation data models on an image.

Parameters:
  • image (np.ndarray) – The image where draw the data.

  • dms (Union[List[DataModels.InstanceSegmentation], DataModels.InstanceSegmentation]) – A list or a single InstanceSegmentation data model.

  • config (dict) – A configuration dict.

Returns:

The input image with the data models drawn.

Return type:

np.ndarray

Visualization.DrawPersonKeypoints module

Visualization.DrawPersonKeypoints.draw(image: ndarray, data_models: List[PersonKeyPoints] | PersonKeyPoints, config: dict) ndarray[source]

Draw PersonKeyPoints data models data on an image.

Parameters:
  • image (np.ndarray) – The image where draw the data.

  • data_models (Union[List[DataModels.PersonKeyPoints], DataModels.PersonKeyPoints]) – A list or a single PersonKeyPoints data model.

  • config (dict) – A configuration dict.

Returns:

The input image with the data models drawn.

Return type:

np.ndarray

Visualization.utils module

class Visualization.utils.TextPosition(value)[source]

Bases: Enum

An enumeration.

BOTTOM_LEFT = 'BOTTOM_LEFT'
BOTTOM_RIGHT = 'BOTTOM_RIGHT'
TOP_LEFT = 'TOP_LEFT'
TOP_RIGHT = 'TOP_RIGHT'
Visualization.utils.draw_bounding_box(image: ndarray, box: BoundingBox | None, thickness: int = 2, color: Tuple[int, int, int] = (0, 0, 255), text: str | None = None, text_scale: int = 2, text_thickness: int = 2, text_color: Tuple[int, int, int] = (0, 0, 0), text_background: bool = True, text_bg_color: Tuple[int, int, int] | None = None, text_bg_alpha: float | None = None, text_line_space: int = 15, text_box_position: TextPosition = TextPosition.TOP_LEFT, text_direction: TextPosition = TextPosition.BOTTOM_RIGHT) ndarray[source]

Draw a bounding box and optional text on an image.

Parameters:
  • image (np.ndarray) – A BGR uint8 image of shape (H, W, 3).

  • box (Optional[BoundingBox]) – A BoundingBox object.

  • thickness (int, optional) – Box line thickness. Defaults to 2.

  • color (Tuple[int, int, int], optional) – BGR line color. Defaults to (0,0,255).

  • text (Optional[str], optional) – Optional text to set along the bounding box. Defaults to None.

  • text_scale (int, optional) – Text scale. Defaults to 2.

  • text_thickness (int, optional) – Text thickness. Defaults to 2.

  • text_color (Tuple[int, int, int], optional) – BGR text color. Defaults to (0,0,0).

  • text_background (bool, optional) – Set a solid color as a background on the area occupied by the text. Defaults to True.

  • text_bg_color (Optional[Tuple[int, int, int]], optional) – Text background BGR color. If None, the bounding box color will be used. Defaults to None.

  • Optional[float] (text_bg_alpha) – Transparency of the text background, where 1.0 is completely opaque and 0 is transparent. Defaults to None.

  • text_line_space (int, optional) – Spacing between text lines. Defaults to 15.

  • text_box_position (TextPosition, optional) – The text position relative to the bounding box. Defaults to TextPosition.TOP_LEFT.

  • text_direction (TextPosition, optional) – Direction of the text. Defaults to TextPosition.BOTTOM_RIGHT.

Returns:

The created image.

Return type:

np.ndarray

Visualization.utils.draw_coco_keypoints(image: ndarray, keypoints: COCOKeypoints, color: Tuple[int, int, int] | None = (0, 0, 255), color_by_label: bool = False, color_mapping: Dict[str, Tuple[int, int, int]] | None = None, keypoint_radius: int | None = 5, connection_rules: List[Tuple[str, str, Tuple[int, int, int]]] | None = None, line_thickness: int = 3, show_names: bool = False, show_conf: bool = True, show_keypoints: bool = True, show_connections: bool = True, text_scale: int = 2, text_thickness: int = 2, text_color: Tuple[int, int, int] = (255, 255, 255), text_bg_color: Tuple[int, int, int] | None = None, text_bg_alpha: float | None = None) ndarray[source]

Draw keypoints and its connections on an image.

Parameters:
  • image (np.ndarray) – A BGR uint8 image of shape (H, W, 3).

  • keypoints (Keypoints.COCOKeypoints) – A Keypoints object.

  • color (Optional[Tuple[int, int, int]], optional) – Color of the keypoints. Defaults to None.

  • color_by_label (bool, optional) – Set the keypoints colors by its label. Defaults to False.

  • color_mapping (Optional[Dict[str, Tuple[int, int, int]]], optional) – Mapping between keypoint names and its color. Defaults to None.

  • keypoint_radius (Optional[int], optional) – Radius of the keypoints. Defaults to 5.

  • connection_rules (Optional[List[Tuple[str, str, Tuple[int, int, int]]]], optional) – List of connections rules (keypoints_name_a, keypoints_name_b, (B, G, R)) Defaults to None.

  • line_thickness (int, optional) – Keypoints line thickness. Defaults to 3.

  • show_names (bool, optional) – Show the names of the keypoints. Defaults to False.

  • show_conf (bool, optional) – Show the keypoint confidence along with its name. Defaults no True.

  • show_keypoints (bool, optional) – Show the keypoints circles. Defaults to True.

  • show_connections (bool, optional) – Show the connection lines. Defaults to True.

  • text_scale (int, optional) – Text scale. Defaults to 2.

  • text_thickness (int, optional) – Text thickness. Defaults to 2.

  • text_color (Tuple[int, int, int], optional) – Text color. Defaults to (255,255,255).

  • text_bg_color (Optional[Tuple[int, int, int]], optional) – Color of the text background. Defaults to None.

  • text_bg_alpha (Optional[float], optional) – Transparency of the text background, where 1.0 is completely opaque and 0 is transparent. Defaults to None.

Returns:

The image with the plotted mask.

Return type:

np.ndarray

Visualization.utils.draw_mask(image: ndarray, mask: SegmentationMask, color: Tuple[int, int, int] | None = (0, 0, 255), alpha: float = 0.5, color_by_label: bool = False, label_id: int | None = None, colors_list: List[Tuple[int, int, int]] | None = None) ndarray[source]

Draw a segmentation mask on an image.

Parameters:
  • image (np.ndarray) – A BGR uint8 image of shape (H, W, 3).

  • mask (SegmentationMask) – A SegmentationMask object.

  • color (Optional[Tuple[int, int, int]]) – Color of the mask. Defaults to (0,0,255).

  • alpha (float, optional) – Transparency of the mask, where 1.0 is completely opaque and 0 is transparent. Defaults to 0.5.

  • color_by_label (bool, optional) – Set the mask color by its label_id. Defaults to False.

  • label_id (Optional[int], optional) – label id associated with the mask; used to chose the color. Defaults to None.

  • colors_list (Optional[List[Tuple[int, int, int]]], optional) – Custom list of colors to chose when color_by_label is set to True. If it is None, a seaborn palette is used. Defaults to None.

Returns:

The image with the plotted mask.

Return type:

np.ndarray

Visualization.utils.draw_text(image: ndarray, text: str, position: Tuple[int, int], color=(255, 255, 255), scale: int = 2, thickness: int = 2, background: bool = False, bg_color: Tuple[int, int, int] = (0, 0, 255), bg_alpha: float | None = 0.5, line_space: int = 15, direction: TextPosition = TextPosition.BOTTOM_RIGHT) ndarray[source]

Draw text on an image.

Parameters:
  • image (np.ndarray) – A BGR uint8 image of shape (H, W, 3).

  • text (str) – The text to draw.

  • position (Tuple[int, int]) – (x, y) absolute image coordinates where draw the text.

  • color (tuple, optional) – BGR color of the text. Defaults to (255,255,255).

  • scale (int, optional) – Text scale. Defaults to 2.

  • thickness (int, optional) – Text thickness. Defaults to 2.

  • background (bool, optional) – Set a solid color as a background on the area occupied by the text. Defaults to False.

  • bg_color (Tuple[int, int, int], optional) – Background BGR color. Defaults to (0,0,255).

  • bg_alpha (Optional[float]) – Transparency of the background, where 1.0 is completely opaque and 0 is transparent. Defaults to None.

  • line_space (int, optional) – Spacing between lines. Defaults to 15.

  • direction (TextPosition, optional) – Text position relative to the text origin. Defaults to TextPosition.BOTTOM_RIGHT.

Returns:

The image with the text inserted.

Return type:

np.ndarray

Module contents