Commit 5aeab6ee authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Accept frame_selector in load methods

parent 056bb2bb
Pipeline #14268 passed with stages
in 13 minutes and 1 second
......@@ -15,7 +15,7 @@ from bob.pad.face.database import msu_mfsd as msu_mfsd_hldi
from bob.bio.video.database.mobio import MobioBioFile
from bob.bio.video import FrameSelector
from bob.bio.video import FrameSelector, FrameContainer
import numpy as np
......
......@@ -5,7 +5,8 @@
#==============================================================================
import bob.bio.video # Used in MIFSPadFile class
# Used in ReplayMobilePadFile class
from bob.bio.video import FrameSelector, FrameContainer
import bob.io.base
import numpy as np
......@@ -26,7 +27,7 @@ class MIFSPadFile(PadFile):
file_id)
#==========================================================================
def load(self, directory=None, extension=None):
def load(self, directory=None, extension=None, frame_selector=FrameSelector(selection_style='all')):
"""
Overridden version of the load method defined in the ``PadFile``.
......@@ -49,9 +50,6 @@ class MIFSPadFile(PadFile):
path = self.make_path(
directory=directory, extension=extension) # path to the file
frame_selector = bob.bio.video.FrameSelector(
selection_style='all'
) # this frame_selector will select all frames from the video file
data = bob.io.base.load(path)
data = np.expand_dims(data, axis=0) # upgrade to 4D (video)
......
......@@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-
#==============================================================================
import bob.bio.video # Used in MsuMfsdPadFile class
# Used in ReplayMobilePadFile class
from bob.bio.video import FrameSelector, FrameContainer
from bob.pad.base.database import PadFile # Used in MsuMfsdPadFile class
......@@ -50,35 +51,7 @@ class MsuMfsdPadFile(PadFile):
file_id=f.id)
#==========================================================================
def convert_arr_to_frame_cont(self, data):
"""
This function converts an input 4D array with frames into FrameContainer,
where each frame is an RGB image. The dimensionality of the input array
is [N_frames, 3, N_rows, N_cols].
**Parameters:**
``data`` : 4D :py:class:`numpy.ndarray`
An input 4D array with frames of the dimensionality:
[N_frames, 3, N_rows, N_cols].
**Returns:**
``frames`` : FrameContainer
Resulting FrameContainer containing RGB frames.
"""
frames = bob.bio.video.FrameContainer(
) # initialize the FrameContainer
for idx, sample in enumerate(data):
frames.add(idx, sample)
return frames
#==========================================================================
def load(self, directory=None, extension=None):
def load(self, directory=None, extension=None, frame_selector=FrameSelector(selection_style='all')):
"""
Overridden version of the load method defined in the ``PadFile``.
......@@ -105,11 +78,7 @@ class MsuMfsdPadFile(PadFile):
video_data_array = self.f.load(
directory=directory, extension=extension)
video_data = self.convert_arr_to_frame_cont(
video_data_array) # the result is now a FrameContainer
return video_data
return frame_selector(video_data_array)
#==============================================================================
......
......@@ -3,7 +3,8 @@
#==============================================================================
import bob.bio.video # Used in ReplayPadFile class
# Used in ReplayMobilePadFile class
from bob.bio.video import FrameSelector, FrameContainer
from bob.pad.base.database import PadFile # Used in ReplayPadFile class
......@@ -48,7 +49,7 @@ class ReplayPadFile(PadFile):
file_id=f.id)
#==========================================================================
def load(self, directory=None, extension='.mov'):
def load(self, directory=None, extension='.mov', frame_selector=FrameSelector(selection_style='all')):
"""
Overridden version of the load method defined in the ``PadFile``.
......@@ -70,10 +71,6 @@ class ReplayPadFile(PadFile):
path = self.f.make_path(
directory=directory, extension=extension) # path to the video file
frame_selector = bob.bio.video.FrameSelector(
selection_style='all'
) # this frame_selector will select all frames from the video file
video_data = frame_selector(path) # video data
return video_data # video data
......
......@@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-
#==============================================================================
import bob.bio.video # Used in ReplayMobilePadFile class
# Used in ReplayMobilePadFile class
from bob.bio.video import FrameSelector, FrameContainer
from bob.pad.base.database import PadFile # Used in ReplayMobilePadFile class
......@@ -46,35 +47,7 @@ class ReplayMobilePadFile(PadFile):
file_id=f.id)
#==========================================================================
def convert_arr_to_frame_cont(self, data):
"""
This function converts an input 4D array with frames into FrameContainer,
where each frame is an RGB image. The dimensionality of the input array
is [N_frames, 3, N_rows, N_cols].
**Parameters:**
``data`` : 4D :py:class:`numpy.ndarray`
An input 4D array with frames of the dimensionality:
[N_frames, 3, N_rows, N_cols].
**Returns:**
``frames`` : FrameContainer
Resulting FrameContainer containing RGB frames.
"""
frames = bob.bio.video.FrameContainer(
) # initialize the FrameContainer
for idx, sample in enumerate(data):
frames.add(idx, sample)
return frames
#==========================================================================
def load(self, directory=None, extension='.mov'):
def load(self, directory=None, extension='.mov', frame_selector=FrameSelector(selection_style='all')):
"""
Overridden version of the load method defined in the ``PadFile``.
......@@ -96,10 +69,7 @@ class ReplayMobilePadFile(PadFile):
video_data_array = self.f.load(
directory=directory, extension=extension)
video_data = self.convert_arr_to_frame_cont(
video_data_array) # the result is now a FrameContainer
return video_data
return frame_selector(video_data_array)
#==============================================================================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment