Commit e588deb4 authored by Olegs NIKISINS's avatar Olegs NIKISINS

Changed missing annotations conditional check + unit tests

parent a9962f1a
Pipeline #17350 passed with stage
in 17 minutes and 32 seconds
......@@ -115,12 +115,14 @@ class Wrapper(bob.bio.base.preprocessor.Preprocessor):
preprocessed : :py:class:`bob.bio.video.FrameContainer`
A frame container that contains the preprocessed frames.
"""
annots = None
fc = utils.FrameContainer()
for index, frame, _ in frames:
# if annotations are given, we take them
if annotations is not None: annots = annotations[index] if index in annotations.keys() else None
annots = None
# if annotations are given, and if particular frame annotations are not missing we take them:
if annotations is not None and index in annotations.keys() and annotations[index]: annots = annotations[index]
# preprocess image (by default: detect a face)
preprocessed = self.preprocessor(frame, annots)
......
......@@ -42,6 +42,42 @@ def test_annotations():
assert numpy.allclose(preprocessed[0][1],
bob.io.base.load(pkg_resources.resource_filename("bob.bio.face.test", "data/cropped.hdf5")))
def test_missing_annotations():
class TestPreproc(bob.bio.base.preprocessor.Preprocessor):
# ==========================================================================
def __init__(self):
super(TestPreproc, self).__init__()
def __call__(self, image, annotations=None):
if annotations is None:
return None
else:
return image.shape[0]
# 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 = 4, selection_style="first")
preprocessor = bob.bio.video.preprocessor.Wrapper(TestPreproc(), frame_selector, compressed_io=False)
video = preprocessor.read_original_data(video_object,
original_path, ".avi")
frame_annots = {'bottomright': (200, 200), 'topleft': (100, 100)}
annotations = {}
annotations["0"] = frame_annots
annotations["1"] = {}
annotations["3"] = frame_annots
preprocessed_video = preprocessor(video, annotations)
assert len(preprocessed_video) == 2
assert preprocessed_video[0][1] == 3
assert [x[0] for x in preprocessed_video] == ['0', '3']
def test_detect():
# load test video
......
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