Skip to content
Snippets Groups Projects
Commit 236bd85b authored by Olegs NIKISINS's avatar Olegs NIKISINS
Browse files

Changed the file implementation in the high level database interface

parent 1b1cadd1
No related branches found
No related tags found
1 merge request!1Added the High Level DB interface for Replay DB + Unit Tests
#!/usr/bin/env python #!/usr/bin/env python2
# vim: set fileencoding=utf-8 : # -*- coding: utf-8 -*-
# Amir Mohammadi <amir.mohammadi@idiap.ch> """
# Fri 10 Jun 2016 16:48:44 CEST Created on Thu May 4 12:03:36 2017
"""Replay attack database implementation as bob.bio.db.Database""" High level implementation for the REPLAY-ATTACK database
@author: Olegs Nikisins <olegs.nikisins@idiap.ch>
"""
#==============================================================================
from bob.pad.voice.database import PadVoiceFile
from bob.pad.base.database import PadDatabase from bob.pad.base.database import PadDatabase
import bob.bio.video # Used in ReplayPadFile class
class ReplayPadFile(PadVoiceFile): from bob.pad.base.database import PadFile # Used in ReplayPadFile class
def __init__(self, f): #==============================================================================
class ReplayPadFile(PadFile):
""" """
Initializes this File object with our own File equivalent A high level implementation of the File class for the REPLAY-ATTACK database.
""" """
self.__f = f def __init__(self, f):
# this f is actually an instance of the File class that is defined in """
# bob.db.replay.models and the PadFile class here needs
# client_id, path, attack_type, file_id for initialization. We have to **Parameters:**
# convert information here and provide them to PadFile. attack_type is a
# little tricky to get here. Based on the documentation of PadFile: ``f`` : :py:class:`object`
# In cased of a spoofed data, this parameter should indicate what kind of spoofed attack it is. An instance of the File class defined in the low level implementation
# The default None value is interpreted that the PadFile is a genuine or real sample. of the Replay database, in the bob.db.replay.models.py file.
if f.is_real(): """
attack_type = None
else: self.f = f
attack_type = 'attack' # this f is actually an instance of the File class that is defined in
# attack_type is a string and I decided to make it like this for this # bob.db.replay.models and the PadFile class here needs
# particular database. You can do whatever you want for your own database. # client_id, path, attack_type, file_id for initialization. We have to
# convert information here and provide them to PadFile. attack_type is a
super(ReplayPadFile, self).__init__(client_id=f.client, path=f.path, # little tricky to get here. Based on the documentation of PadFile:
attack_type=attack_type, file_id=f.id) # In cased of a spoofed data, this parameter should indicate what kind of spoofed attack it is.
# The default None value is interpreted that the PadFile is a genuine or real sample.
if f.is_real():
attack_type = None
else:
attack_type = 'attack'
# attack_type is a string and I decided to make it like this for this
# particular database. You can do whatever you want for your own database.
super(ReplayPadFile, self).__init__(client_id=f.client, path=f.path,
attack_type=attack_type, file_id=f.id)
def load(self, directory=None, extension='.mov'):
"""
Overridden version of the load method defined in the ``bob.db.base.File``.
**Parameters:**
``directory`` : :py:class:`str`
String containing the path to the Replay database.
``extension`` : :py:class:`str`
Extension of the video files in the Replay database.
**Returns:**
``filtered_image`` : :py:class:`dict`
A dictionary containing the key-value pairs: "video" key containing the frames data,
and "bbx" containing the coordinates of the face bounding boxes for each frame.
"""
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
bbx_data = self.f.bbx(directory=directory) # numpy array containing the face bounding box data for each video frame, returned data format described in the f.bbx() method of the low level interface
return_dictionary = {}
return_dictionary["video"] = video_data
return_dictionary["bbx"] = bbx_data
return return_dictionary # dictionary containing the face bounding box annotations and video data
#==============================================================================
class ReplayPadDatabase(PadDatabase): class ReplayPadDatabase(PadDatabase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment