77
88
99def 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
1311) -> List [int ]:
1412 """Checks and adjusts bounding box coordinates to fit within image boundaries.
1513
@@ -37,7 +35,7 @@ def draw_rectangle(
3735 bbox_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
3836 thickness : int = 3 ,
3937 is_opaque : bool = False ,
40- alpha : float = 0.5
38+ alpha : float = 0.5 ,
4139) -> np .ndarray :
4240 """Draws a rectangle around an object in the image.
4341
@@ -105,7 +103,7 @@ def add_label(
105103 # Calculate background rectangle dimensions
106104 bg_width = text_width + 2 * padding
107105 bg_height = text_height + 2 * padding
108-
106+
109107 # Calculate background rectangle position
110108 bg_x1 = bbox [0 ]
111109 bg_y1 = bbox [1 ] - bg_height # Removed the gap by removing (5 * size)
@@ -138,7 +136,7 @@ def add_label(
138136 # Calculate background rectangle dimensions
139137 bg_width = text_width + 2 * padding
140138 bg_height = text_height + 2 * padding
141-
139+
142140 # Calculate background rectangle position
143141 bg_x1 = bbox [0 ]
144142 bg_y1 = bbox [1 ]
@@ -203,7 +201,7 @@ def add_T_label(
203201 label , font , size , thickness
204202 )
205203 padding = 5 # Padding around text
206-
204+
207205 # draw vertical line
208206 x_center = (bbox [0 ] + bbox [2 ]) // 2
209207 line_top = y_top = bbox [1 ] - 50
@@ -219,11 +217,11 @@ def add_T_label(
219217 return add_label (img , label , bbox )
220218
221219 cv2 .line (img , (x_center , bbox [1 ]), (x_center , line_top ), text_bg_color , 3 )
222-
220+
223221 # Calculate background rectangle dimensions
224222 bg_width = label_width + 2 * padding
225223 bg_height = label_height + 2 * padding
226-
224+
227225 # Calculate background rectangle position
228226 bg_x1 = x_center - (bg_width // 2 )
229227 bg_y1 = y_top
@@ -336,7 +334,7 @@ def draw_multiple_rectangles(
336334 bbox_color : Tuple [int , int , int ] = (255 , 255 , 255 ),
337335 thickness : int = 3 ,
338336 is_opaque : bool = False ,
339- alpha : float = 0.5
337+ alpha : float = 0.5 ,
340338) -> np .ndarray :
341339 """Draws multiple rectangles on the image.
342340
0 commit comments