diff --git a/bob/pad/face/config/frame_diff_svm.py b/bob/pad/face/config/frame_diff_svm.py index 6d8ad4f259ca6f275cd75d6d73c88279bd839a04..53b500ab6569e760000a0ead3cc9e7ce3f48fe4d 100644 --- a/bob/pad/face/config/frame_diff_svm.py +++ b/bob/pad/face/config/frame_diff_svm.py @@ -22,12 +22,10 @@ this resource. from ..preprocessor import FrameDifference NUMBER_OF_FRAMES = None # process all frames -CHECK_FACE_SIZE_FLAG = True # Check size of the face MIN_FACE_SIZE = 50 # Minimal size of the face to consider preprocessor = FrameDifference( number_of_frames=NUMBER_OF_FRAMES, - check_face_size_flag=CHECK_FACE_SIZE_FLAG, min_face_size=MIN_FACE_SIZE) """ In the preprocessing stage the frame differences are computed for both facial and non-facial/background diff --git a/bob/pad/face/config/frame_diff_svm_aggregated_db.py b/bob/pad/face/config/frame_diff_svm_aggregated_db.py index 30834c4fe6d293a65edc63a4628ef813042850ca..bfc018637f8a5dbad94433651879dbd9a56ac5b2 100644 --- a/bob/pad/face/config/frame_diff_svm_aggregated_db.py +++ b/bob/pad/face/config/frame_diff_svm_aggregated_db.py @@ -24,12 +24,10 @@ this resource. from ..preprocessor import FrameDifference NUMBER_OF_FRAMES = None # process all frames -CHECK_FACE_SIZE_FLAG = True # Check size of the face MIN_FACE_SIZE = 50 # Minimal size of the face to consider preprocessor = FrameDifference( number_of_frames=NUMBER_OF_FRAMES, - check_face_size_flag=CHECK_FACE_SIZE_FLAG, min_face_size=MIN_FACE_SIZE) """ In the preprocessing stage the frame differences are computed for both facial and non-facial/background diff --git a/bob/pad/face/preprocessor/FrameDifference.py b/bob/pad/face/preprocessor/FrameDifference.py index 638597be8a03eb95155a6e71cbc75724b0ce04ca..05037679862ba0579f537f78dfc06c6c2bf286e9 100644 --- a/bob/pad/face/preprocessor/FrameDifference.py +++ b/bob/pad/face/preprocessor/FrameDifference.py @@ -19,11 +19,13 @@ import bob.ip.base import bob.ip.color +import bob.ip.facedetect + #============================================================================== # Main body: -class FrameDifference(Preprocessor, object): +class FrameDifference(Preprocessor): """ This class is designed to compute frame differences for both facial and background regions. The constraint of minimal size of the face can be @@ -39,10 +41,6 @@ class FrameDifference(Preprocessor, object): The number of frames to extract the frame differences from. If ``None``, all frames of the input video are used. Default: ``None``. - ``check_face_size_flag`` : :py:class:`bool` - If True, only return the frames containing faces of the size above the - specified threshold ``min_face_size``. Default: ``False``. - ``min_face_size`` : :py:class:`int` The minimal size of the face in pixels. Only valid when ``check_face_size_flag`` is set to True. Default: 50. @@ -50,16 +48,15 @@ class FrameDifference(Preprocessor, object): def __init__(self, number_of_frames=None, - check_face_size_flag=False, - min_face_size=50): + min_face_size=50, + **kwargs): super(FrameDifference, self).__init__( number_of_frames=number_of_frames, - check_face_size_flag=check_face_size_flag, - min_face_size=min_face_size) + min_face_size=min_face_size, + **kwargs) self.number_of_frames = number_of_frames - self.check_face_size_flag = check_face_size_flag self.min_face_size = min_face_size #========================================================================== @@ -148,13 +145,17 @@ class FrameDifference(Preprocessor, object): else: y1 = annotations['topleft'][0] - border - if y1 < 0: y1 = 0 + if y1 < 0: + y1 = 0 x1 = annotations['topleft'][1] - border - if x1 < 0: x1 = 0 + if x1 < 0: + x1 = 0 y2 = y1 + height + (2 * border) - if y2 > full_diff.shape[0]: y2 = full_diff.shape[0] + if y2 > full_diff.shape[0]: + y2 = full_diff.shape[0] x2 = x1 + width + (2 * border) - if x2 > full_diff.shape[1]: x2 = full_diff.shape[1] + if x2 > full_diff.shape[1]: + x2 = full_diff.shape[1] full = full_diff[y1:y2, x1:x2].sum() full_size = full_diff[y1:y2, x1:x2].size @@ -167,7 +168,7 @@ class FrameDifference(Preprocessor, object): bg = full - face normalization = float(full_size - face_diff.size) - if normalization < 1: #prevents zero division + if normalization < 1: # prevents zero division bg = 0.0 else: bg /= float(full_size - face_diff.size) @@ -217,8 +218,15 @@ class FrameDifference(Preprocessor, object): for idx in range(0, len(annotations)): # idx - frame index - frame_annotations = annotations[str( - idx)] # annotations for particular frame + # annotations for particular frame + frame_annotations = annotations[str(idx)] + + # Estimate bottomright and topleft if they are not available: + if 'topleft' not in frame_annotations: + bbx = bob.ip.facedetect.bounding_box_from_annotation( + **frame_annotations) + frame_annotations['topleft'] = bbx.topleft + frame_annotations['bottomright'] = bbx.bottomright # size of current face face_size = np.min( @@ -357,7 +365,7 @@ class FrameDifference(Preprocessor, object): cleaned_annotations = {} for idx, valid_frame_num in enumerate(valid_frames): - ## valid_frame_num - is the number of the original frame having annotations + # valid_frame_num - is the number of the original frame having annotations cleaned_annotations[str(idx)] = annotations[str( valid_frame_num)] # correct the frame numbers @@ -375,8 +383,7 @@ class FrameDifference(Preprocessor, object): This method calls the ``comp_face_bg_diff`` function of this class computing the frame differences for both facial and background regions. The frame differences are computed for selected frames, which are returned - by ``check_face_size`` function of this class. This ``check_face_size`` is - done only if ``check_face_size_flag = True``. + by ``check_face_size`` function of this class. **Parameters:** @@ -400,14 +407,12 @@ class FrameDifference(Preprocessor, object): if len(frames) != len(annotations): # if some annotations are missing - ## Select only annotated frames: + # Select only annotated frames: frames, annotations = self.select_annotated_frames( frames, annotations) - if self.check_face_size_flag: - - selected_frames, selected_annotations = self.check_face_size( - frames, annotations, self.min_face_size) + selected_frames, selected_annotations = self.check_face_size( + frames, annotations, self.min_face_size) diff = self.comp_face_bg_diff( frames=selected_frames, diff --git a/conda/meta.yaml b/conda/meta.yaml index 37ee4302a64b7d35b4c228387ddff61e5414b11e..7918a1a946d2574713733593aa86d230dbcca183 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -20,14 +20,10 @@ requirements: host: - python {{ python }} - setuptools {{ setuptools }} - - six {{ six }} - - sphinx {{ sphinx }} - - numpy {{ numpy }} - bob.extension - bob.bio.base - bob.io.base - bob.ip.base - - scikit-learn - bob.pad.base - bob.bio.face - bob.bio.video @@ -41,7 +37,6 @@ requirements: - python - setuptools - six - - sphinx - numpy - scikit-learn diff --git a/requirements.txt b/requirements.txt index 9518917ce953e255d508bf20116ce3eac9e5f92c..afa566eb706bc577fc6fc313a3fa4397a762677e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ setuptools six -sphinx numpy bob.extension bob.bio.base