@@ -165,38 +165,17 @@ def get_prediction(face_image):
165165 ]
166166 results = []
167167
168- # for single person
169- if not self .multi_person :
170- h , w , _ = source_image .shape
171- source_image = cv2 .resize (source_image , (IMAGE_SIZE , IMAGE_SIZE )) / 255.0
172- predictions = get_prediction (source_image )
173- imageio .mimsave (os .path .join (self .output , self .filename ), [
174- cv2 .resize ((frame * 255.0 ).astype ('uint8' ), (h , w ))
175- for frame in predictions
176- ],
177- fps = fps )
178- return
179-
180168 bboxes = self .extract_bbox (source_image .copy ())
181169 print (str (len (bboxes )) + " persons have been detected" )
182- if len (bboxes ) <= 1 :
183- h , w , _ = source_image .shape
184- source_image = cv2 .resize (source_image , (IMAGE_SIZE , IMAGE_SIZE )) / 255.0
185- predictions = get_prediction (source_image )
186- imageio .mimsave (os .path .join (self .output , self .filename ), [
187- cv2 .resize ((frame * 255.0 ).astype ('uint8' ), (h , w ))
188- for frame in predictions
189- ],
190- fps = fps )
191- return
192170
193171 # for multi person
194172 for rec in bboxes :
195173 face_image = source_image .copy ()[rec [1 ]:rec [3 ], rec [0 ]:rec [2 ]]
196174 face_image = cv2 .resize (face_image , (IMAGE_SIZE , IMAGE_SIZE )) / 255.0
197175 predictions = get_prediction (face_image )
198176 results .append ({'rec' : rec , 'predict' : predictions })
199-
177+ if len (bboxes ) == 1 or not self .multi_person :
178+ break
200179 out_frame = []
201180
202181 for i in range (len (driving_video )):
@@ -209,6 +188,7 @@ def get_prediction(face_image):
209188 out = cv2 .resize (out .astype (np .uint8 ), (x2 - x1 , y2 - y1 ))
210189 if len (results ) == 1 :
211190 frame [y1 :y2 , x1 :x2 ] = out
191+ break
212192 else :
213193 patch = np .zeros (frame .shape ).astype ('uint8' )
214194 patch [y1 :y2 , x1 :x2 ] = out
0 commit comments