@@ -28,6 +28,7 @@ def __init__(self, cfg, model_path, logger, device="cpu:0"):
2828 self .pipeline = Pipeline (cfg .data .val .pipeline , cfg .data .val .keep_ratio )
2929
3030 def inference (self , img ):
31+ self .image = img .copy ()
3132 img_info = {"id" : 0 }
3233 if isinstance (img , str ):
3334 img_info ["file_name" ] = os .path .basename (img )
@@ -63,18 +64,17 @@ def visualize(self, dets, meta, class_names, score_thres, wait=0):
6364 bboxes , confidences , class_ids = infotrans (all_box )
6465 print ("viz time: {:.3f}s" .format (time .time () - time1 ))
6566 self .class_names = dict (zip (class_ids ,class_names ))
66- image = meta ["raw_img" ][0 ].copy ()
6767 np .random .seed (12345 )
6868 for bb , conf , cid in zip (bboxes , confidences , class_ids ):
6969 bbox_colors = {key : np .random .randint (0 , 255 , size = (3 ,)).tolist () for key in self .class_names .keys ()}
7070 clr = [int (c ) for c in bbox_colors [cid ]]
71- cv2 .rectangle (image , (bb [0 ], bb [1 ]), (bb [0 ] + bb [2 ], bb [1 ] + bb [3 ]), clr , 2 )
71+ cv2 .rectangle (self . image , (bb [0 ], bb [1 ]), (bb [0 ] + bb [2 ], bb [1 ] + bb [3 ]), clr , 2 )
7272 label = "{}:{:.4f}" .format (self .class_names [cid ], conf )
7373 (label_width , label_height ), baseLine = cv2 .getTextSize (label , cv2 .FONT_HERSHEY_SIMPLEX , 0.5 , 2 )
7474 y_label = max (bb [1 ], label_height )
75- cv2 .rectangle (image , (bb [0 ], y_label - label_height ), (bb [0 ] + label_width , y_label + baseLine ),
75+ cv2 .rectangle (self . image , (bb [0 ], y_label - label_height ), (bb [0 ] + label_width , y_label + baseLine ),
7676 (255 , 255 , 255 ), cv2 .FILLED )
77- cv2 .putText (image , label , (bb [0 ], y_label ), cv2 .FONT_HERSHEY_SIMPLEX , 0.5 , clr , 2 )
77+ cv2 .putText (self . image , label , (bb [0 ], y_label ), cv2 .FONT_HERSHEY_SIMPLEX , 0.5 , clr , 2 )
7878 bboxes = np .array (bboxes ).astype ('int' )
7979 confidences = np .array (confidences )
80- return bboxes , confidences , class_ids , image
80+ return bboxes , confidences , class_ids , self . image
0 commit comments