API Reference¶
Rectangle Drawing¶
draw_rectangle ¶
draw_rectangle(img: NDArray[uint8], bbox: Sequence[float], bbox_color: tuple[int, int, int] = (255, 255, 255), thickness: int = 3, is_opaque: bool = False, alpha: float = 0.5, bbox_format: str = 'voc') -> 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
|
Sequence[float]
|
Bounding box coordinates in |
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
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with drawn rectangle; the input image is not modified |
Source code in bbox_visualizer/core/rectangle.py
draw_multiple_rectangles ¶
draw_multiple_rectangles(img: NDArray[uint8], bboxes: Sequence[Sequence[float]], bbox_color: tuple[int, int, int] | Sequence[tuple[int, int, int]] = (255, 255, 255), thickness: int = 3, is_opaque: bool = False, alpha: float = 0.5, bbox_format: str = 'voc') -> 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
|
Sequence[Sequence[float]]
|
List of bounding boxes, each in |
required |
bbox_color
|
tuple[int, int, int] | Sequence[tuple[int, int, int]]
|
BGR color tuple applied to all boxes, or a sequence of one color per box (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
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with all rectangles drawn; the input image is not modified |
Source code in bbox_visualizer/core/rectangle.py
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 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 | |
Label Drawing¶
add_label ¶
add_label(img: NDArray[uint8], label: str, bbox: Sequence[float], 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, bbox_format: str = 'voc') -> 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
|
Sequence[float]
|
Bounding box coordinates in |
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
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with added label; the input image is not modified |
Source code in bbox_visualizer/core/labels.py
add_multiple_labels ¶
add_multiple_labels(img: NDArray[uint8], labels: list[str], bboxes: Sequence[Sequence[float]], 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, bbox_format: str = 'voc') -> 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
|
Sequence[Sequence[float]]
|
List of bounding boxes, each in |
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
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with all labels added; the input image is not modified |
Source code in bbox_visualizer/core/labels.py
Special Labels¶
add_T_label ¶
add_T_label(img: NDArray[uint8], label: str, bbox: Sequence[float], 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), bbox_format: str = 'voc') -> 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
|
Sequence[float]
|
Bounding box coordinates in |
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)
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with added T-shaped label; the input image is not modified |
Source code in bbox_visualizer/core/flags.py
add_multiple_T_labels ¶
add_multiple_T_labels(img: NDArray[uint8], labels: list[str], bboxes: Sequence[Sequence[float]], draw_bg: bool = True, text_bg_color: tuple[int, int, int] = (255, 255, 255), text_color: tuple[int, int, int] = (0, 0, 0), bbox_format: str = 'voc') -> 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
|
Sequence[Sequence[float]]
|
List of bounding boxes, each in |
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)
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with all T-shaped labels added; the input image is not modified |
Source code in bbox_visualizer/core/flags.py
draw_flag_with_label ¶
draw_flag_with_label(img: NDArray[uint8], label: str, bbox: Sequence[float], 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), bbox_format: str = 'voc') -> 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
|
Sequence[float]
|
Bounding box coordinates in |
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)
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with added flag label; the input image is not modified |
Source code in bbox_visualizer/core/flags.py
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
draw_multiple_flags_with_labels ¶
draw_multiple_flags_with_labels(img: NDArray[uint8], labels: list[str], bboxes: Sequence[Sequence[float]], 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), bbox_format: str = 'voc') -> 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
|
Sequence[Sequence[float]]
|
List of bounding boxes, each in |
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)
|
bbox_format
|
str
|
Input bbox format, one of "voc", "coco", "yolo" (default: "voc") |
'voc'
|
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
New image with all flag labels added; the input image is not modified |