@@ -92,21 +92,30 @@ def predict(self, image, request_id=0, draw=False):
9292 )
9393 status = self .exec_network .requests [request_id ].wait (- 1 )
9494 if status == 0 :
95+ predict_start_time = time .time ()
9596 pred_result = self .exec_network .requests [request_id ].outputs [
9697 self .output_name
9798 ]
98- return pred_result
99+ predict_end_time = (time .time () - predict_start_time ) * 1000
100+ if draw :
101+ self .preprocess_output (pred_result , image , show_bbox = draw )
102+ return (predict_end_time , pred_result )
99103
100104 @abc .abstractmethod
101- def preprocess_output (self , inference_results , image ):
105+ def preprocess_output (self , inference_results , image , show_bbox = False ):
102106 """Draw bounding boxes onto the frame."""
103107 pass
104108
105109 @staticmethod
106110 @abc .abstractmethod
107- def draw_output (coords , image ):
111+ def draw_output (image , ):
108112 pass
109113
114+ def add_text (self , text , frame , position , font_size = 0.75 , color = (255 , 255 , 255 )):
115+ cv2 .putText (
116+ frame , text , position , cv2 .FONT_HERSHEY_COMPLEX , font_size , color , 1 ,
117+ )
118+
110119 def preprocess_input (self , image ):
111120 """Helper function for processing frame"""
112121 p_frame = cv2 .resize (image , (self .input_shape [3 ], self .input_shape [2 ]))
@@ -122,7 +131,7 @@ class Face_Detection(Base):
122131 def __init__ (self , model_name , device = "CPU" , threshold = 0.60 , extensions = None ):
123132 super ().__init__ (model_name , device = "CPU" , threshold = 0.60 , extensions = None )
124133
125- def preprocess_output (self , inference_results , image ):
134+ def preprocess_output (self , inference_results , image , show_bbox = False ):
126135 """Draw bounding boxes onto the frame."""
127136 if not (self ._init_image_w and self ._init_image_h ):
128137 raise RuntimeError ("Initial image width and height cannot be None." )
@@ -136,10 +145,13 @@ def preprocess_output(self, inference_results, image):
136145 xmax = int (box [5 ] * self ._init_image_w )
137146 ymax = int (box [6 ] * self ._init_image_h )
138147 coords .append ((xmin , ymin , xmax , ymax ))
148+ if show_bbox :
149+ self .draw_output (image , xmin , ymin , xmax , ymax )
139150 return coords , image
140151
141- def draw_output (coords , image ):
142- label = "Person"
152+ @staticmethod
153+ def draw_output (image , xmin , ymin , xmax , ymax ):
154+ label = "Person's Face"
143155 bbox_color = (0 , 255 , 0 )
144156 padding_size = (0.05 , 0.25 )
145157 text_color = (255 , 255 , 255 )
0 commit comments