API Reference¶
Warning Control¶
suppress_warnings ¶
Suppress or enable warning messages from bbox-visualizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
suppress
|
bool
|
If True, suppress all warnings. If False, enable warnings. |
True
|
Source code in bbox_visualizer/core/_utils.py
warnings_suppressed ¶
Temporarily suppress warnings.
Example
Source code in bbox_visualizer/core/_utils.py
Rectangle Drawing¶
draw_rectangle ¶
draw_rectangle(img: NDArray[uint8], bbox: list[int], bbox_color: tuple[int, int, int] = (255, 255, 255), thickness: int = 3, is_opaque: bool = False, alpha: float = 0.5) -> NDArray[np.uint8]
Draws a rectangle around an object in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
bbox
|
list[int]
|
List of [x_min, y_min, x_max, y_max] coordinates |
required |
bbox_color
|
tuple[int, int, int]
|
BGR color tuple for the box (default: white) |
(255, 255, 255)
|
thickness
|
int
|
Line thickness in pixels (default: 3) |
3
|
is_opaque
|
bool
|
If True, draws filled rectangle with transparency (default: False) |
False
|
alpha
|
float
|
Transparency level for filled rectangles (default: 0.5) |
0.5
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with drawn rectangle |
Source code in bbox_visualizer/core/rectangle.py
draw_multiple_rectangles ¶
draw_multiple_rectangles(img: NDArray[uint8], bboxes: list[list[int]], bbox_color: tuple[int, int, int] = (255, 255, 255), thickness: int = 3, is_opaque: bool = False, alpha: float = 0.5) -> NDArray[np.uint8]
Draws multiple rectangles on the image using optimized batched operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
bboxes
|
list[list[int]]
|
List of bounding boxes, each containing [x_min, y_min, x_max, y_max] |
required |
bbox_color
|
tuple[int, int, int]
|
BGR color tuple for the boxes (default: white) |
(255, 255, 255)
|
thickness
|
int
|
Line thickness in pixels (default: 3) |
3
|
is_opaque
|
bool
|
If True, draws filled rectangles with transparency (default: False) |
False
|
alpha
|
float
|
Transparency level for filled rectangles (default: 0.5) |
0.5
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with all rectangles drawn |
Source code in bbox_visualizer/core/rectangle.py
Label Drawing¶
add_label ¶
add_label(img: NDArray[uint8], label: str, bbox: list[int], size: float = 1, thickness: int = 2, draw_bg: bool = True, text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0), top: bool = True) -> NDArray[np.uint8]
Add a label to a bounding box, either above or inside it.
If there isn't enough space above the box, the label is placed inside. The label has an optional background rectangle for better visibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
label
|
str
|
Text to display |
required |
bbox
|
list[int]
|
List of [x_min, y_min, x_max, y_max] coordinates |
required |
size
|
float
|
Font size multiplier (default: 1) |
1
|
thickness
|
int
|
Text thickness in pixels (default: 2) |
2
|
draw_bg
|
bool
|
Whether to draw background rectangle (default: True) |
True
|
text_bg_color
|
tuple[int, int, int]
|
BGR color tuple for text background (default: white) |
(255, 255, 255)
|
text_color
|
tuple[int, int, int]
|
BGR color tuple for text (default: black) |
(0, 0, 0)
|
top
|
bool
|
If True, place label above box; if False, inside (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with added label |
Source code in bbox_visualizer/core/labels.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
add_multiple_labels ¶
add_multiple_labels(img: NDArray[uint8], labels: list[str], bboxes: list[list[int]], size: float = 1, thickness: int = 2, draw_bg: bool = True, text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0), top: bool = True) -> NDArray[np.uint8]
Add multiple labels to their corresponding bounding boxes using optimized operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
labels
|
list[str]
|
List of text labels |
required |
bboxes
|
list[list[int]]
|
List of bounding boxes, each containing [x_min, y_min, x_max, y_max] |
required |
size
|
float
|
Font size multiplier (default: 1) |
1
|
thickness
|
int
|
Text thickness in pixels (default: 2) |
2
|
draw_bg
|
bool
|
Whether to draw background rectangles (default: True) |
True
|
text_bg_color
|
tuple[int, int, int]
|
BGR color tuple for text backgrounds (default: white) |
(255, 255, 255)
|
text_color
|
tuple[int, int, int]
|
BGR color tuple for text (default: black) |
(0, 0, 0)
|
top
|
bool
|
If True, place labels above boxes; if False, inside (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with all labels added |
Source code in bbox_visualizer/core/labels.py
Special Labels¶
add_T_label ¶
add_T_label(img: NDArray[uint8], label: str, bbox: list[int], size: float = 1, thickness: int = 2, draw_bg: bool = True, text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0)) -> NDArray[np.uint8]
Add a T-shaped label with a vertical line connecting to the bounding box.
The label consists of a vertical line extending from the top of the box and a horizontal label at the top. Falls back to regular label if there isn't enough space above the box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
label
|
str
|
Text to display |
required |
bbox
|
list[int]
|
List of [x_min, y_min, x_max, y_max] coordinates |
required |
size
|
float
|
Font size multiplier (default: 1) |
1
|
thickness
|
int
|
Text thickness in pixels (default: 2) |
2
|
draw_bg
|
bool
|
Whether to draw background rectangle (default: True) |
True
|
text_bg_color
|
tuple[int, int, int]
|
BGR color tuple for text background (default: white) |
(255, 255, 255)
|
text_color
|
tuple[int, int, int]
|
BGR color tuple for text (default: black) |
(0, 0, 0)
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with added T-shaped label |
Source code in bbox_visualizer/core/flags.py
add_multiple_T_labels ¶
add_multiple_T_labels(img: NDArray[uint8], labels: list[str], bboxes: list[list[int]], draw_bg: bool = True, text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0)) -> NDArray[np.uint8]
Add multiple T-shaped labels to their corresponding bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
labels
|
list[str]
|
List of text labels |
required |
bboxes
|
list[list[int]]
|
List of bounding boxes, each containing [x_min, y_min, x_max, y_max] |
required |
draw_bg
|
bool
|
Whether to draw background rectangles (default: True) |
True
|
text_bg_color
|
tuple[int, int, int]
|
BGR color tuple for text backgrounds (default: white) |
(255, 255, 255)
|
text_color
|
tuple[int, int, int]
|
BGR color tuple for text (default: black) |
(0, 0, 0)
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with all T-shaped labels added |
Source code in bbox_visualizer/core/flags.py
draw_flag_with_label ¶
draw_flag_with_label(img: NDArray[uint8], label: str, bbox: list[int], size: float = 1, thickness: int = 2, write_label: bool = True, line_color: tuple[int, int, int] = (255, 255, 255), text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0)) -> NDArray[np.uint8]
Draws a flag-like label with a vertical line and text box.
The flag consists of a vertical line extending from the middle of the box and a horizontal label at the top. Falls back to regular label if there isn't enough space above the box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
label
|
str
|
Text to display |
required |
bbox
|
list[int]
|
List of [x_min, y_min, x_max, y_max] coordinates |
required |
size
|
float
|
Font size multiplier (default: 1) |
1
|
thickness
|
int
|
Text thickness in pixels (default: 2) |
2
|
write_label
|
bool
|
Whether to draw the text label (default: True) |
True
|
line_color
|
tuple[int, int, int]
|
BGR color tuple for the vertical line (default: white) |
(255, 255, 255)
|
text_bg_color
|
tuple[int, int, int]
|
BGR color tuple for text background (default: white) |
(255, 255, 255)
|
text_color
|
tuple[int, int, int]
|
BGR color tuple for text (default: black) |
(0, 0, 0)
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with added flag label |
Source code in bbox_visualizer/core/flags.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
draw_multiple_flags_with_labels ¶
draw_multiple_flags_with_labels(img: NDArray[uint8], labels: list[str], bboxes: list[list[int]], write_label: bool = True, line_color: tuple[int, int, int] = (255, 255, 255), text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0)) -> NDArray[np.uint8]
Add multiple flag-like labels to their corresponding bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
NDArray[uint8]
|
Input image array |
required |
labels
|
list[str]
|
List of text labels |
required |
bboxes
|
list[list[int]]
|
List of bounding boxes, each containing [x_min, y_min, x_max, y_max] |
required |
write_label
|
bool
|
Whether to draw the text labels (default: True) |
True
|
line_color
|
tuple[int, int, int]
|
BGR color tuple for the vertical lines (default: white) |
(255, 255, 255)
|
text_bg_color
|
tuple[int, int, int]
|
BGR color tuple for text backgrounds (default: white) |
(255, 255, 255)
|
text_color
|
tuple[int, int, int]
|
BGR color tuple for text (default: black) |
(0, 0, 0)
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
Image with all flag labels added |