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