Skip to content

Commit a5c396d

Browse files
committed
refactor: update type hints
1 parent ab5e7fb commit a5c396d

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

bbox_visualizer/core/_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Internal utilities for bbox-visualizer."""
22

33
from contextlib import contextmanager
4+
from typing import Generator
45

56
# Global flag to track warning suppression state
67
_warnings_suppressed: bool = False
@@ -18,7 +19,7 @@ def suppress_warnings(suppress: bool = True) -> None:
1819

1920

2021
@contextmanager
21-
def warnings_suppressed():
22+
def warnings_suppressed() -> Generator[None, None, None]:
2223
"""Temporarily suppress warnings.
2324
2425
Example:

bbox_visualizer/core/flags.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import cv2
66
import numpy as np
7+
from numpy.typing import NDArray
78

89
from ._utils import _check_and_modify_bbox, _should_suppress_warning, _validate_color
910
from .labels import add_label
@@ -13,15 +14,15 @@
1314

1415

1516
def add_T_label(
16-
img: np.ndarray,
17+
img: NDArray[np.uint8],
1718
label: str,
1819
bbox: list[int],
1920
size: float = 1,
2021
thickness: int = 2,
2122
draw_bg: bool = True,
2223
text_bg_color: tuple[int, int, int] = (255, 255, 255),
2324
text_color: tuple[int, int, int] = (0, 0, 0),
24-
) -> np.ndarray:
25+
) -> NDArray[np.uint8]:
2526
"""Add a T-shaped label with a vertical line connecting to the bounding box.
2627
2728
The label consists of a vertical line extending from the top of the box
@@ -98,7 +99,7 @@ def add_T_label(
9899

99100

100101
def draw_flag_with_label(
101-
img: np.ndarray,
102+
img: NDArray[np.uint8],
102103
label: str,
103104
bbox: list[int],
104105
size: float = 1,
@@ -107,7 +108,7 @@ def draw_flag_with_label(
107108
line_color: tuple[int, int, int] = (255, 255, 255),
108109
text_bg_color: tuple[int, int, int] = (255, 255, 255),
109110
text_color: tuple[int, int, int] = (0, 0, 0),
110-
) -> np.ndarray:
111+
) -> NDArray[np.uint8]:
111112
"""Draws a flag-like label with a vertical line and text box.
112113
113114
The flag consists of a vertical line extending from the middle of the box
@@ -183,13 +184,13 @@ def draw_flag_with_label(
183184

184185

185186
def add_multiple_T_labels(
186-
img: np.ndarray,
187+
img: NDArray[np.uint8],
187188
labels: list[str],
188189
bboxes: list[list[int]],
189190
draw_bg: bool = True,
190191
text_bg_color: tuple[int, int, int] = (255, 255, 255),
191192
text_color: tuple[int, int, int] = (0, 0, 0),
192-
) -> np.ndarray:
193+
) -> NDArray[np.uint8]:
193194
"""Add multiple T-shaped labels to their corresponding bounding boxes.
194195
195196
Args:
@@ -227,14 +228,14 @@ def add_multiple_T_labels(
227228

228229

229230
def draw_multiple_flags_with_labels(
230-
img: np.ndarray,
231+
img: NDArray[np.uint8],
231232
labels: list[str],
232233
bboxes: list[list[int]],
233234
write_label: bool = True,
234235
line_color: tuple[int, int, int] = (255, 255, 255),
235236
text_bg_color: tuple[int, int, int] = (255, 255, 255),
236237
text_color: tuple[int, int, int] = (0, 0, 0),
237-
) -> np.ndarray:
238+
) -> NDArray[np.uint8]:
238239
"""Add multiple flag-like labels to their corresponding bounding boxes.
239240
240241
Args:

bbox_visualizer/core/labels.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import cv2
44
import numpy as np
5+
from numpy.typing import NDArray
56

67
from ._utils import _check_and_modify_bbox, _validate_color
78

89
font = cv2.FONT_HERSHEY_SIMPLEX
910

1011

1112
def add_label(
12-
img: np.ndarray,
13+
img: NDArray[np.uint8],
1314
label: str,
1415
bbox: list[int],
1516
size: float = 1,
@@ -18,7 +19,7 @@ def add_label(
1819
text_bg_color: tuple[int, int, int] = (255, 255, 255),
1920
text_color: tuple[int, int, int] = (0, 0, 0),
2021
top: bool = True,
21-
) -> np.ndarray:
22+
) -> NDArray[np.uint8]:
2223
"""Add a label to a bounding box, either above or inside it.
2324
2425
If there isn't enough space above the box, the label is placed inside.
@@ -116,7 +117,7 @@ def add_label(
116117

117118

118119
def add_multiple_labels(
119-
img: np.ndarray,
120+
img: NDArray[np.uint8],
120121
labels: list[str],
121122
bboxes: list[list[int]],
122123
size: float = 1,
@@ -125,7 +126,7 @@ def add_multiple_labels(
125126
text_bg_color: tuple[int, int, int] = (255, 255, 255),
126127
text_color: tuple[int, int, int] = (0, 0, 0),
127128
top: bool = True,
128-
) -> np.ndarray:
129+
) -> NDArray[np.uint8]:
129130
"""Add multiple labels to their corresponding bounding boxes.
130131
131132
Args:

bbox_visualizer/core/rectangle.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import cv2
44
import numpy as np
5+
from numpy.typing import NDArray
56

67
from ._utils import _check_and_modify_bbox, _validate_color
78

89

910
def draw_rectangle(
10-
img: np.ndarray,
11+
img: NDArray[np.uint8],
1112
bbox: list[int],
1213
bbox_color: tuple[int, int, int] = (255, 255, 255),
1314
thickness: int = 3,
1415
is_opaque: bool = False,
1516
alpha: float = 0.5,
16-
) -> np.ndarray:
17+
) -> NDArray[np.uint8]:
1718
"""Draws a rectangle around an object in the image.
1819
1920
Args:
@@ -45,13 +46,13 @@ def draw_rectangle(
4546

4647

4748
def draw_multiple_rectangles(
48-
img: np.ndarray,
49+
img: NDArray[np.uint8],
4950
bboxes: list[list[int]],
5051
bbox_color: tuple[int, int, int] = (255, 255, 255),
5152
thickness: int = 3,
5253
is_opaque: bool = False,
5354
alpha: float = 0.5,
54-
) -> np.ndarray:
55+
) -> NDArray[np.uint8]:
5556
"""Draws multiple rectangles on the image.
5657
5758
Args:

0 commit comments

Comments
 (0)