Commit 162adc27 authored by Manuel Günther's avatar Manuel Günther

New version of loading video files

parent 760f5fd8
Pipeline #4200 passed with stages
in 63 minutes and 14 seconds
......@@ -3,12 +3,8 @@
# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# Wed 20 July 14:43:22 CEST 2016
"""
Verification API for bob.db.voxforge
"""
from bob.bio.base.database.file import BioFile
from bob.bio.video.utils.FrameSelector import FrameSelector
from ..utils import FrameSelector
class VideoBioFile(BioFile):
......@@ -19,8 +15,5 @@ class VideoBioFile(BioFile):
"""
super(VideoBioFile, self).__init__(client_id=client_id, path=path, file_id=file_id)
def load(self, directory=None, extension='.avi'):
return FrameSelector()(self.make_path(directory, extension))
def load(self, directory=None, extension='.avi', frame_selector = FrameSelector()):
return frame_selector(self.make_path(directory, extension))
......@@ -42,9 +42,9 @@ class Wrapper(bob.bio.base.preprocessor.Preprocessor):
This is experimental and might cause trouble.
Use this flag with care.
read_original_data:
read_original_data: callable or ``None``
Function that loads the raw data.
If not explicitly defined the raw data will be loaded by :py:method:`bob.bio.base.database.VideoBioFile.load`
If not explicitly defined the raw data will be loaded by :py:method:`bob.bio.base.database.VideoBioFile.load`. using the specified ``frame_selector``
"""
......@@ -53,9 +53,16 @@ class Wrapper(bob.bio.base.preprocessor.Preprocessor):
frame_selector=utils.FrameSelector(),
quality_function=None,
compressed_io=False,
read_original_data=lambda biofile, directory, extension: biofile.load(directory, extension)
read_original_data=None
):
def _read_video_data(biofile, directory, extension):
"""Read video data using the frame_selector of this object"""
return biofile.load(directory, extension, frame_selector)
if read_original_data is None:
read_original_data = _read_video_data
# load preprocessor configuration
if isinstance(preprocessor, str):
self.preprocessor = bob.bio.base.load_resource(preprocessor, "preprocessor")
......@@ -64,6 +71,7 @@ class Wrapper(bob.bio.base.preprocessor.Preprocessor):
else:
raise ValueError("The given preprocessor could not be interpreted")
bob.bio.base.preprocessor.Preprocessor.__init__(
self,
preprocessor=preprocessor,
......@@ -72,7 +80,6 @@ class Wrapper(bob.bio.base.preprocessor.Preprocessor):
read_original_data=read_original_data
)
self.frame_selector = frame_selector
self.quality_function = quality_function
self.compressed_io = compressed_io
......@@ -107,9 +114,6 @@ class Wrapper(bob.bio.base.preprocessor.Preprocessor):
preprocessed : :py:class:`bob.bio.video.FrameContainer`
A frame container that contains the preprocessed frames.
"""
if not isinstance(frames, utils.FrameContainer):
frames = self.frame_selector(frames)
annots = None
fc = utils.FrameContainer()
......
......@@ -8,7 +8,7 @@ import os
class DummyBioFile(VideoBioFile):
def load(self, directory=None, extension='.pgm'):
def load(self, directory=None, extension='.pgm', frame_selector=None):
file_name = self.make_path(directory, extension)
fc = FrameContainer()
fc.add(os.path.basename(file_name), bob.io.base.load(file_name))
......
......@@ -44,16 +44,12 @@ def test_annotations():
def test_detect():
def read_original_data(video_object, original_path, original_extension):
return frame_selector(video_object.make_path(original_path, original_extension))
# load test video
original_path = pkg_resources.resource_filename("bob.bio.video.test", "")
video_object = bob.bio.video.database.VideoBioFile(client_id=1, file_id=1, path="data/testvideo")
frame_selector = bob.bio.video.FrameSelector(max_number_of_frames=3, selection_style="spread")
preprocessor = bob.bio.video.preprocessor.Wrapper('face-detect', frame_selector, compressed_io=False,
read_original_data=read_original_data)
preprocessor = bob.bio.video.preprocessor.Wrapper('face-detect', frame_selector, compressed_io=False)
video = preprocessor.read_original_data(video_object, original_path,".avi")
assert isinstance(video, bob.bio.video.FrameContainer)
......@@ -71,15 +67,11 @@ def test_detect():
def test_flandmark():
def read_original_data(video_object, original_path, original_extension):
return frame_selector(video_object.make_path(original_path, original_extension))
original_path = pkg_resources.resource_filename("bob.bio.video.test", "")
video_object = bob.bio.video.database.VideoBioFile(client_id=1, file_id=1, path="data/testvideo")
frame_selector = bob.bio.video.FrameSelector(max_number_of_frames=3, selection_style="spread")
preprocessor = bob.bio.video.preprocessor.Wrapper('landmark-detect', frame_selector, compressed_io=False,
read_original_data=read_original_data)
preprocessor = bob.bio.video.preprocessor.Wrapper('landmark-detect', frame_selector, compressed_io=False)
video = preprocessor.read_original_data(video_object, original_path, ".avi")
assert isinstance(video, bob.bio.video.FrameContainer)
......
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