From 8ef95fe25e5359d7fd254436e320a1ff2d51430a Mon Sep 17 00:00:00 2001
From: Olegs NIKISINS <onikisins@italix03.idiap.ch>
Date: Wed, 28 Feb 2018 15:51:46 +0100
Subject: [PATCH] Removed VideoQualityMeasure, replaced with Wraper

---
 .../config/extractor/video_quality_measure.py |   7 +-
 bob/pad/face/config/qm_lr.py                  |   6 +-
 bob/pad/face/config/qm_one_class_gmm.py       |   6 +-
 .../config/qm_one_class_svm_aggregated_db.py  |   6 +-
 .../qm_one_class_svm_cascade_aggregated_db.py |   6 +-
 bob/pad/face/config/qm_svm.py                 |   6 +-
 bob/pad/face/config/qm_svm_aggregated_db.py   |   6 +-
 bob/pad/face/extractor/VideoQualityMeasure.py | 135 ------------------
 bob/pad/face/extractor/__init__.py            |   2 -
 bob/pad/face/test/test.py                     |   6 +-
 10 files changed, 31 insertions(+), 155 deletions(-)
 delete mode 100644 bob/pad/face/extractor/VideoQualityMeasure.py

diff --git a/bob/pad/face/config/extractor/video_quality_measure.py b/bob/pad/face/config/extractor/video_quality_measure.py
index f5cc5598..fc9af42b 100644
--- a/bob/pad/face/config/extractor/video_quality_measure.py
+++ b/bob/pad/face/config/extractor/video_quality_measure.py
@@ -1,6 +1,8 @@
 #!/usr/bin/env python
 
-from bob.pad.face.extractor import VideoQualityMeasure
+from bob.pad.face.extractor import ImageQualityMeasure
+
+import bob.bio.video
 
 #=======================================================================================
 # Define instances here:
@@ -9,5 +11,4 @@ galbally = True
 msu = True
 dtype = None
 
-video_quality_measure_galbally_msu = VideoQualityMeasure(
-    galbally=galbally, msu=msu, dtype=dtype)
+video_quality_measure_galbally_msu = bob.bio.video.extractor.Wrapper(ImageQualityMeasure(galbally=galbally, msu=msu, dtype=dtype))
diff --git a/bob/pad/face/config/qm_lr.py b/bob/pad/face/config/qm_lr.py
index 92ae1985..19a5d422 100644
--- a/bob/pad/face/config/qm_lr.py
+++ b/bob/pad/face/config/qm_lr.py
@@ -54,13 +54,15 @@ facial image, which is defined by ``RGB_OUTPUT_FLAG = True``.
 #=======================================================================================
 # define extractor:
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
+
+from bob.bio.video.extractor import Wrapper
 
 GALBALLY = True
 MSU = True
 DTYPE = None
 
-extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+extractor = Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 """
 In the feature extraction stage the Image Quality Measures are extracted from each frame of the preprocessed RGB video.
 The features to be computed are introduced in the following papers: [WHJ15]_ and [CBVM16]_.
diff --git a/bob/pad/face/config/qm_one_class_gmm.py b/bob/pad/face/config/qm_one_class_gmm.py
index 16a44c01..182c71bb 100644
--- a/bob/pad/face/config/qm_one_class_gmm.py
+++ b/bob/pad/face/config/qm_one_class_gmm.py
@@ -54,13 +54,15 @@ facial image, which is defined by ``RGB_OUTPUT_FLAG = True``.
 #=======================================================================================
 # define extractor:
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
+
+from bob.bio.video.extractor import Wrapper
 
 GALBALLY = True
 MSU = True
 DTYPE = None
 
-extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+extractor = Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 """
 In the feature extraction stage the Image Quality Measures are extracted from each frame of the preprocessed RGB video.
 The features to be computed are introduced in the following papers: [WHJ15]_ and [CBVM16]_.
diff --git a/bob/pad/face/config/qm_one_class_svm_aggregated_db.py b/bob/pad/face/config/qm_one_class_svm_aggregated_db.py
index efebc108..1216d66b 100644
--- a/bob/pad/face/config/qm_one_class_svm_aggregated_db.py
+++ b/bob/pad/face/config/qm_one_class_svm_aggregated_db.py
@@ -56,13 +56,15 @@ facial image, which is defined by ``RGB_OUTPUT_FLAG = True``.
 #=======================================================================================
 # define extractor:
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
+
+from bob.bio.video.extractor import Wrapper
 
 GALBALLY = True
 MSU = True
 DTYPE = None
 
-extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+extractor = Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 """
 In the feature extraction stage the Image Quality Measures are extracted from each frame of the preprocessed RGB video.
 The features to be computed are introduced in the following papers: [WHJ15]_ and [CBVM16]_.
diff --git a/bob/pad/face/config/qm_one_class_svm_cascade_aggregated_db.py b/bob/pad/face/config/qm_one_class_svm_cascade_aggregated_db.py
index 6b63e29d..7fcc6122 100644
--- a/bob/pad/face/config/qm_one_class_svm_cascade_aggregated_db.py
+++ b/bob/pad/face/config/qm_one_class_svm_cascade_aggregated_db.py
@@ -56,13 +56,15 @@ facial image, which is defined by ``RGB_OUTPUT_FLAG = True``.
 #=======================================================================================
 # define extractor:
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
+
+from bob.bio.video.extractor import Wrapper
 
 GALBALLY = True
 MSU = True
 DTYPE = None
 
-extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+extractor = Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 """
 In the feature extraction stage the Image Quality Measures are extracted from each frame of the preprocessed RGB video.
 The features to be computed are introduced in the following papers: [WHJ15]_ and [CBVM16]_.
diff --git a/bob/pad/face/config/qm_svm.py b/bob/pad/face/config/qm_svm.py
index 609ab7de..961a413f 100644
--- a/bob/pad/face/config/qm_svm.py
+++ b/bob/pad/face/config/qm_svm.py
@@ -54,13 +54,15 @@ facial image, which is defined by ``RGB_OUTPUT_FLAG = True``.
 #=======================================================================================
 # define extractor:
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
+
+from bob.bio.video.extractor import Wrapper
 
 GALBALLY = True
 MSU = True
 DTYPE = None
 
-extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+extractor = Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 """
 In the feature extraction stage the Image Quality Measures are extracted from each frame of the preprocessed RGB video.
 The features to be computed are introduced in the following papers: [WHJ15]_ and [CBVM16]_.
diff --git a/bob/pad/face/config/qm_svm_aggregated_db.py b/bob/pad/face/config/qm_svm_aggregated_db.py
index 01199315..481c50b8 100644
--- a/bob/pad/face/config/qm_svm_aggregated_db.py
+++ b/bob/pad/face/config/qm_svm_aggregated_db.py
@@ -56,13 +56,15 @@ facial image, which is defined by ``RGB_OUTPUT_FLAG = True``.
 #=======================================================================================
 # define extractor:
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
+
+from bob.bio.video.extractor import Wrapper
 
 GALBALLY = True
 MSU = True
 DTYPE = None
 
-extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+extractor = Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 """
 In the feature extraction stage the Image Quality Measures are extracted from each frame of the preprocessed RGB video.
 The features to be computed are introduced in the following papers: [WHJ15]_ and [CBVM16]_.
diff --git a/bob/pad/face/extractor/VideoQualityMeasure.py b/bob/pad/face/extractor/VideoQualityMeasure.py
deleted file mode 100644
index a48e0589..00000000
--- a/bob/pad/face/extractor/VideoQualityMeasure.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
-"""
-Created on Wed May 31 16:39:34 2017
-
-@author: Olegs Nikisins
-"""
-
-#==============================================================================
-# Import what is needed here:
-
-from bob.bio.base.extractor import Extractor
-
-from bob.pad.face.extractor import ImageQualityMeasure
-
-import bob.bio.video
-
-from bob.pad.face.extractor import VideoDataLoader
-
-import six
-
-#==============================================================================
-# Main body:
-
-
-class VideoQualityMeasure(Extractor, object):
-    """
-    This class is designed to extract Quality Measures for each frame in the
-    input color video. For further documentation and description of features,
-    see "bob.ip.qualitymeasure".
-
-    **Parameters:**
-
-    ``galbally`` : :py:class:`bool`
-        If ``True``, galbally features will be added to the features.
-        Default: ``True``.
-
-    ``msu`` : :py:class:`bool`
-        If ``True``, MSU features will be added to the features.
-        Default: ``True``.
-
-    ``dtype`` : numpy.dtype
-        The data type of the resulting feature vector.
-        Default: ``None``.
-    """
-
-    #==========================================================================
-    def __init__(self, galbally=True, msu=True, dtype=None, **kwargs):
-
-        super(VideoQualityMeasure, self).__init__(
-            galbally=galbally, msu=msu, dtype=dtype)
-
-        self.galbally = galbally
-        self.msu = msu
-        self.dtype = dtype
-
-        # extractor to process a single image/frame:
-        extractor = ImageQualityMeasure(
-            galbally=galbally, msu=msu, dtype=dtype)
-
-        # a wrapper allowing to apply above extractor to the whole video:
-        self.video_extractor = bob.bio.video.extractor.Wrapper(extractor)
-
-    #==========================================================================
-    def __call__(self, frames):
-        """
-        Extract feature vectors containing Quality Measures for each frame
-        in the input color video sequence/container. The resulting features
-        will be saved to the FrameContainer too.
-
-        **Parameters:**
-
-        ``frames`` : FrameContainer or string.
-            Video data stored in the FrameContainer,
-            see ``bob.bio.video.utils.FrameContainer`` for further details.
-            If string, the name of the file to load the video data from is
-            defined in it. String is possible only when empty preprocessor is
-            used. In this case video data is loaded directly from the database.
-
-        **Returns:**
-
-        ``quality_measures`` : FrameContainer
-            Quality Measures for each frame stored in the FrameContainer.
-        """
-
-        if isinstance(frames, six.string_types):  # if frames is a path(!)
-
-            video_loader = VideoDataLoader()
-
-            frames = video_loader(frames)  # frames is now a FrameContainer
-
-
-#        import ipdb; ipdb.set_trace()
-
-        quality_measures = self.video_extractor(frames=frames)
-
-        return quality_measures
-
-    #==========================================================================
-    def write_feature(self, frames, file_name):
-        """
-        Writes the given data (that has been generated using the __call__ function of this class) to file.
-        This method overwrites the write_data() method of the Extractor class.
-
-        **Parameters:**
-
-        ``frames`` :
-            Data returned by the __call__ method of the class.
-
-        ``file_name`` : :py:class:`str`
-            Name of the file.
-        """
-
-        self.video_extractor.write_feature(frames, file_name)
-
-    #==========================================================================
-    def read_feature(self, file_name):
-        """
-        Reads the preprocessed data from file.
-        This method overwrites the read_data() method of the Extractor class.
-
-        **Parameters:**
-
-        ``file_name`` : :py:class:`str`
-            Name of the file.
-
-        **Returns:**
-
-        ``frames`` : :py:class:`bob.bio.video.FrameContainer`
-            Frames stored in the frame container.
-        """
-
-        frames = self.video_extractor.read_feature(file_name)
-
-        return frames
diff --git a/bob/pad/face/extractor/__init__.py b/bob/pad/face/extractor/__init__.py
index b8da75a8..e754647b 100644
--- a/bob/pad/face/extractor/__init__.py
+++ b/bob/pad/face/extractor/__init__.py
@@ -2,7 +2,6 @@ from .LBPHistogram import LBPHistogram
 from .VideoLBPHistogram import VideoLBPHistogram
 from .ImageQualityMeasure import ImageQualityMeasure
 from .VideoDataLoader import VideoDataLoader
-from .VideoQualityMeasure import VideoQualityMeasure
 from .FrameDiffFeatures import FrameDiffFeatures
 
 
@@ -28,7 +27,6 @@ __appropriate__(
     LBPHistogram,
     VideoLBPHistogram,
     ImageQualityMeasure,
-    VideoQualityMeasure,
     VideoDataLoader,
     FrameDiffFeatures,
 )
diff --git a/bob/pad/face/test/test.py b/bob/pad/face/test/test.py
index c66dadd5..ac4e4297 100644
--- a/bob/pad/face/test/test.py
+++ b/bob/pad/face/test/test.py
@@ -28,7 +28,7 @@ from ..extractor import FrameDiffFeatures
 
 from ..extractor import VideoLBPHistogram
 
-from ..extractor import VideoQualityMeasure
+from ..extractor import ImageQualityMeasure
 
 from ..utils import face_detection_utils
 
@@ -369,7 +369,7 @@ def test_video_lbp_histogram():
 #==============================================================================
 def test_video_quality_measure():
     """
-    Test VideoQualityMeasure extractor.
+    Test ImageQualityMeasure with Wrapper extractor.
     """
 
     image = load(datafile('test_image.png', 'bob.pad.face.test'))
@@ -381,7 +381,7 @@ def test_video_quality_measure():
     MSU = True
     DTYPE = None
 
-    extractor = VideoQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE)
+    extractor = bob.bio.video.extractor.Wrapper(ImageQualityMeasure(galbally=GALBALLY, msu=MSU, dtype=DTYPE))
 
     features = extractor(video)
 
-- 
GitLab