7
7
8
8
9
9
def check_and_modify_bbox (
10
- bbox : List [int ],
11
- img_size : Tuple [int , int , int ],
12
- margin : int = 0
10
+ bbox : List [int ], img_size : Tuple [int , int , int ], margin : int = 0
13
11
) -> List [int ]:
14
12
"""Checks and adjusts bounding box coordinates to fit within image boundaries.
15
13
@@ -37,7 +35,7 @@ def draw_rectangle(
37
35
bbox_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
38
36
thickness : int = 3 ,
39
37
is_opaque : bool = False ,
40
- alpha : float = 0.5
38
+ alpha : float = 0.5 ,
41
39
) -> np .ndarray :
42
40
"""Draws a rectangle around an object in the image.
43
41
@@ -105,7 +103,7 @@ def add_label(
105
103
# Calculate background rectangle dimensions
106
104
bg_width = text_width + 2 * padding
107
105
bg_height = text_height + 2 * padding
108
-
106
+
109
107
# Calculate background rectangle position
110
108
bg_x1 = bbox [0 ]
111
109
bg_y1 = bbox [1 ] - bg_height # Removed the gap by removing (5 * size)
@@ -138,7 +136,7 @@ def add_label(
138
136
# Calculate background rectangle dimensions
139
137
bg_width = text_width + 2 * padding
140
138
bg_height = text_height + 2 * padding
141
-
139
+
142
140
# Calculate background rectangle position
143
141
bg_x1 = bbox [0 ]
144
142
bg_y1 = bbox [1 ]
@@ -203,7 +201,7 @@ def add_T_label(
203
201
label , font , size , thickness
204
202
)
205
203
padding = 5 # Padding around text
206
-
204
+
207
205
# draw vertical line
208
206
x_center = (bbox [0 ] + bbox [2 ]) // 2
209
207
line_top = y_top = bbox [1 ] - 50
@@ -219,11 +217,11 @@ def add_T_label(
219
217
return add_label (img , label , bbox )
220
218
221
219
cv2 .line (img , (x_center , bbox [1 ]), (x_center , line_top ), text_bg_color , 3 )
222
-
220
+
223
221
# Calculate background rectangle dimensions
224
222
bg_width = label_width + 2 * padding
225
223
bg_height = label_height + 2 * padding
226
-
224
+
227
225
# Calculate background rectangle position
228
226
bg_x1 = x_center - (bg_width // 2 )
229
227
bg_y1 = y_top
@@ -336,7 +334,7 @@ def draw_multiple_rectangles(
336
334
bbox_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
337
335
thickness : int = 3 ,
338
336
is_opaque : bool = False ,
339
- alpha : float = 0.5
337
+ alpha : float = 0.5 ,
340
338
) -> np .ndarray :
341
339
"""Draws multiple rectangles on the image.
342
340
0 commit comments