@@ -89,10 +89,32 @@ def visualize_results(self, image, bboxes, scores, scaling=(1, 1)):
8989 if len (bbox ) != 4 :
9090 continue
9191
92- # TODO: scale bounding box with scale factor (see resize function)
93- # HINT: the y axis comes first in bounding boxes, order is [top(y), left(x), bottom(y), right(x)]
94-
95- # TODO: visualize the found item with a rectangle and render the score as text
96-
92+ # scale bounding box with scale factor
93+ bbox = [bbox [0 ] * scaling [1 ], bbox [1 ] * scaling [0 ], bbox [2 ] * scaling [1 ], bbox [3 ] * scaling [0 ]]
94+ bbox = list (map (lambda x : int (round (x )), bbox ))
95+
96+ width = bbox [3 ] - bbox [1 ]
97+ height = bbox [2 ] - bbox [0 ]
98+
99+ thickness = self .thickness_base + round (max (image .shape ) * self .thickness_scale )
100+ cv2 .rectangle (image , (bbox [1 ], bbox [0 ]), (bbox [1 ] + width , bbox [0 ] + height ), self .color , thickness )
101+
102+ font_scaling = self .font_size_base + round (max (image .shape ) * self .font_scale )
103+ text_thickness = round (self .font_thickness_factor * thickness )
104+ score_text = format (float (score ), ".2f" )
105+ text_size = cv2 .getTextSize (score_text , self .font , font_scaling , text_thickness )[0 ]
106+ text_start = bbox [1 ] + width - text_size [0 ], bbox [0 ]
107+ text_end = bbox [1 ] + width , bbox [0 ] - text_size [1 ]
108+ cv2 .rectangle (image , text_start , text_end , self .color , - 1 )
109+ cv2 .putText (
110+ image ,
111+ score_text ,
112+ text_start ,
113+ self .font ,
114+ font_scaling ,
115+ (255 , 255 , 255 ),
116+ bottomLeftOrigin = False ,
117+ thickness = text_thickness
118+ )
97119 return image
98120
0 commit comments