From 359cde0cbc99f66ae75bc590569efe08f4d506b5 Mon Sep 17 00:00:00 2001
From: Olegs NIKISINS <onikisins@italix03.idiap.ch>
Date: Tue, 17 Oct 2017 14:57:11 +0200
Subject: [PATCH] Fixed no face detected issue in VideoFaceCrop

---
 bob/pad/face/preprocessor/VideoFaceCrop.py | 10 +++++++++-
 bob/pad/face/utils/face_detection_utils.py | 14 ++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/bob/pad/face/preprocessor/VideoFaceCrop.py b/bob/pad/face/preprocessor/VideoFaceCrop.py
index 97024f8d..756bac3e 100644
--- a/bob/pad/face/preprocessor/VideoFaceCrop.py
+++ b/bob/pad/face/preprocessor/VideoFaceCrop.py
@@ -276,7 +276,15 @@ class VideoFaceCrop(Preprocessor, object):
 
         if self.detect_faces_flag:
 
-            annotations = detect_faces_in_video(frames)
+            annotations_detected = detect_faces_in_video(frames)
+
+            if not annotations_detected:
+
+                annotations = annotations # if now annotations detected use DB annotations
+
+            else:
+
+                annotations = annotations_detected # if face was detected overwrite DB annotations
 
         if len(frames) != len(annotations): # if some annotations are missing
 
diff --git a/bob/pad/face/utils/face_detection_utils.py b/bob/pad/face/utils/face_detection_utils.py
index 1bfff767..c088f3ba 100644
--- a/bob/pad/face/utils/face_detection_utils.py
+++ b/bob/pad/face/utils/face_detection_utils.py
@@ -25,19 +25,14 @@ def detect_face_in_image(image):
     ``annotations`` : :py:class:`dict`
         A dictionary containing annotations of the face bounding box.
         Dictionary must be as follows ``{'topleft': (row, col), 'bottomright': (row, col)}``.
+        If no annotations found an empty dictionary is returned.
     """
 
     data = bob.ip.dlib.FaceDetector().detect_single_face(image)
 
     annotations = {}
 
-    if data is None:
-
-        annotations['topleft'] = (0, 0)
-
-        annotations['bottomright'] = (0, 0)
-
-    else:
+    if data is not None:
 
         bounding_box = data[0]
 
@@ -65,6 +60,7 @@ def detect_faces_in_video(frame_container):
         Dictionary structure: ``annotations = {'1': frame1_dict, '2': frame1_dict, ...}``.
         Where ``frameN_dict = {'topleft': (row, col), 'bottomright': (row, col)}``
         is the dictionary defining the coordinates of the face bounding box in frame N.
+        If no annotations found an empty dictionary is returned.
     """
 
     annotations = {}
@@ -75,7 +71,9 @@ def detect_faces_in_video(frame_container):
 
         frame_annotations = detect_face_in_image(image)
 
-        annotations[str(idx)] = frame_annotations
+        if frame_annotations:
+
+            annotations[str(idx)] = frame_annotations
 
     return annotations
 
-- 
GitLab