bbox-visualizer:¶
bbox-visualizer helps you easily draw bounding boxes with their corresponding labels after detecting them using any object detection method. The bounding boxes are expected to be in the format (xmin, ymin, xmax, ymax)
.
Usage¶
import bbox_visualizer as bbv
-
bbox_visualizer.bbox_visualizer.
add_T_label
(img, label, bbox, size=1, thickness=2, draw_bg=True, text_bg_color=(255, 255, 255), text_color=(0, 0, 0))[source]¶ adds a T label to the rectangle, originating from the top of the rectangle
Parameters: - img (ndarray) – the image on which the T label is to be written/drawn, preferably the image with the rectangular bounding box drawn
- label (str) – the text (label) to be written
- bbox (list) – a list containing x_min, y_min, x_max and y_max of the rectangle positions
- size (int, optional) – size of the label, by default 1
- thickness (int, optional) – thickness of the label, by default 2
- draw_bg (bool, optional) – if True, draws the background of the text, else just the text is written, by default True
- text_bg_color (tuple, optional) – the background color of the label that is filled, by default (255, 255, 255)
- text_color (tuple, optional) – color of the text (label) to be written, by default (0, 0, 0)
Returns: the image with the T label drawn/written
Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
add_label
(img, label, bbox, size=1, thickness=2, draw_bg=True, text_bg_color=(255, 255, 255), text_color=(0, 0, 0), top=True)[source]¶ adds label, inside or outside the rectangle
Parameters: - img (ndarray) – the image on which the label is to be written, preferably the image with the rectangular bounding box drawn
- label (str) – the text (label) to be written
- bbox (list) – a list containing x_min, y_min, x_max and y_max of the rectangle positions
- size (int, optional) – size of the label, by default 1
- thickness (int, optional) – thickness of the label, by default 2
- draw_bg (bool, optional) – if True, draws the background of the text, else just the text is written, by default True
- text_bg_color (tuple, optional) – the background color of the label that is filled, by default (255, 255, 255)
- text_color (tuple, optional) – color of the text (label) to be written, by default (0, 0, 0)
- top (bool, optional) – if True, writes the label on top of the bounding box, else inside, by default True
Returns: the image with the label written
Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
add_multiple_T_labels
(img, labels, bboxes, draw_bg=True, text_bg_color=(255, 255, 255), text_color=(0, 0, 0))[source]¶ adds T labels to the rectangles, each originating from the top of the rectangle
Parameters: - img (ndarray) – the image on which the T labels are to be written/drawn, preferably the image with the rectangular bounding boxes drawn
- labels (list) – the texts (labels) to be written
- bboxes (list) – a list of lists, each inner list containing x_min, y_min, x_max and y_max of the rectangle positions
- draw_bg (bool, optional) – if True, draws the background of the texts, else just the texts are written, by default True
- text_bg_color (tuple, optional) – the background color of the labels that are filled, by default (255, 255, 255)
- text_color (tuple, optional) – color of the texts (labels) to be written, by default (0, 0, 0)
Returns: the image with the T labels drawn/written
Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
add_multiple_labels
(img, labels, bboxes, size=1, thickness=2, draw_bg=True, text_bg_color=(255, 255, 255), text_color=(0, 0, 0), top=True)[source]¶ add labels, inside or outside the rectangles
Parameters: - img (ndarray) – the image on which the labels are to be written, preferably the image with the rectangular bounding boxes drawn
- labels (list) – a list of string of the texts (labels) to be written
- bboxes (list) – a list of lists, each inner list containing x_min, y_min, x_max and y_max of the rectangle positions
- draw_bg (bool, optional) – if True, draws the background of the texts, else just the texts are written, by default True
- text_bg_color (tuple, optional) – the background color of the labels that are filled, by default (255, 255, 255)
- text_color (tuple, optional) – color of the texts (labels) to be written, by default (0, 0, 0)
- top (bool, optional) – if True, writes the labels on top of the bounding boxes, else inside, by default True
Returns: the image with the labels written
Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
draw_flag_with_label
(img, label, bbox, size=1, thickness=2, write_label=True, line_color=(255, 255, 255), text_bg_color=(255, 255, 255), text_color=(0, 0, 0))[source]¶ draws a pole from the middle of the object that is to be labeled and adds the label to the flag
Parameters: - img (ndarray) – the image on which the flag is to be drawn
- label (str) – label that is written inside the flag
- bbox (list) – a list containing x_min, y_min, x_max and y_max of the rectangle positions
- size (int, optional) – size of the label, by default 1
- thickness (int, optional) – thickness of the label, by default 2
- write_label (bool, optional) – if True, writes the label, otherwise, it’s just a vertical line, by default True
- line_color (tuple, optional) – the color of the pole of the flag, by default (255, 255, 255)
- text_bg_color (tuple, optional) – the background color of the label that is filled, by default (255, 255, 255)
- text_color (tuple, optional) – color of the text (label) to be written, by default (0, 0, 0)
Returns: the image with flag drawn and the label written in the flag
Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
draw_multiple_flags_with_labels
(img, labels, bboxes, write_label=True, line_color=(255, 255, 255), text_bg_color=(255, 255, 255), text_color=(0, 0, 0))[source]¶ draws poles from the middle of the objects that are to be labeled and adds the labels to the flags
Parameters: - img (ndarray) – the image on which the flags are to be drawn
- labels (list) – labels that are written inside the flags
- bbox (list) – a list of lists, each inner list containing x_min, y_min, x_max and y_max of the rectangle positions
- write_label (bool, optional) – if True, writes the labels, otherwise, it’s just a vertical line for each object, by default True
- line_color (tuple, optional) – the color of the pole of the flags, by default (255, 255, 255)
- text_bg_color (tuple, optional) – the background color of the labels that are filled, by default (255, 255, 255)
- text_color (tuple, optional) – color of the texts (labels) to be written, by default (0, 0, 0)
Returns: the image with flags drawn and the labels written in the flags
Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
draw_multiple_rectangles
(img, bboxes, bbox_color=(255, 255, 255), thickness=3, is_opaque=False, alpha=0.5)[source]¶ draws multiple rectangles
- img : ndarray
- the actual image
- bboxes : list
- a list of lists, each inner list containing x_min, y_min, x_max and y_max of the rectangle positions
- bbox_color : tuple, optional
- the color of the boxes, by default (255,255,255)
- thickness : int, optional
- thickness of the outline of the boxes, by default 3
- is_opaque : bool, optional
- if False, draws solid rectangular outlines for rectangles. Else, filled rectangles which are semi transparent, by default False
- alpha : float, optional
- strength of the opacity, by default 0.5
Returns: the image with the bounding boxes drawn Return type: ndarray
-
bbox_visualizer.bbox_visualizer.
draw_rectangle
(img, bbox, bbox_color=(255, 255, 255), thickness=3, is_opaque=False, alpha=0.5)[source]¶ Draws the rectangle around the object
Parameters: - img (ndarray) – the actual image
- bbox (list) – a list containing x_min, y_min, x_max and y_max of the rectangle positions
- bbox_color (tuple, optional) – the color of the box, by default (255,255,255)
- thickness (int, optional) – thickness of the outline of the box, by default 3
- is_opaque (bool, optional) – if False, draws a solid rectangular outline. Else, a filled rectangle which is semi transparent, by default False
- alpha (float, optional) – strength of the opacity, by default 0.5
Returns: the image with the bounding box drawn
Return type: ndarray