verafinger.py 2.38 KB
Newer Older
1 2
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
3
# Tue 27 Sep 2016 16:48:57 CEST
4 5


6 7
from bob.bio.base.database import BioFile, BioDatabase

8 9
from . import AnnotatedArray

10

André Anjos's avatar
André Anjos committed
11
class File(BioFile):
Amir Mohammadi's avatar
Amir Mohammadi committed
12 13
    """
    Implements extra properties of vein files for the Vera Fingervein database
14 15


Amir Mohammadi's avatar
Amir Mohammadi committed
16
    Parameters:
17

Amir Mohammadi's avatar
Amir Mohammadi committed
18
        f (object): Low-level file (or sample) object that is kept inside
19

Amir Mohammadi's avatar
Amir Mohammadi committed
20
    """
21

Amir Mohammadi's avatar
Amir Mohammadi committed
22
    def __init__(self, f):
23

Amir Mohammadi's avatar
Amir Mohammadi committed
24
        super(File, self).__init__(client_id=f.unique_finger_name, path=f.path,
25
            file_id=f.id)
Amir Mohammadi's avatar
Amir Mohammadi committed
26
        self.__f = f
27

28

Amir Mohammadi's avatar
Amir Mohammadi committed
29 30
    def load(self, *args, **kwargs):
        """(Overrides base method) Loads both image and mask"""
31

Amir Mohammadi's avatar
Amir Mohammadi committed
32
        image = super(File, self).load(*args, **kwargs)
33 34 35
        roi = self.__f.roi()
        mask = poly_to_mask(image.shape, roi)
        return AnnotatedArray(image, metadata=dict(mask=mask, roi=roi))
36 37


André Anjos's avatar
André Anjos committed
38
class Database(BioDatabase):
Amir Mohammadi's avatar
Amir Mohammadi committed
39 40 41
    """
    Implements verification API for querying Vera Fingervein database.
    """
42

Amir Mohammadi's avatar
Amir Mohammadi committed
43
    def __init__(self, **kwargs):
André Anjos's avatar
André Anjos committed
44

Amir Mohammadi's avatar
Amir Mohammadi committed
45 46 47
        super(Database, self).__init__(name='verafinger', **kwargs)
        from bob.db.verafinger.query import Database as LowLevelDatabase
        self._db = LowLevelDatabase()
48

Amir Mohammadi's avatar
Amir Mohammadi committed
49 50
        self.low_level_group_names = ('train', 'dev')
        self.high_level_group_names = ('world', 'dev')
51

Amir Mohammadi's avatar
Amir Mohammadi committed
52
    def groups(self):
André Anjos's avatar
André Anjos committed
53

Amir Mohammadi's avatar
Amir Mohammadi committed
54
        return self.convert_names_to_highlevel(self._db.groups(),
55
            self.low_level_group_names, self.high_level_group_names)
56

Amir Mohammadi's avatar
Amir Mohammadi committed
57 58
    def client_id_from_model_id(self, model_id, group='dev'):
        """Required as ``model_id != client_id`` on this database"""
59

Amir Mohammadi's avatar
Amir Mohammadi committed
60
        return self._db.finger_name_from_model_id(model_id)
André Anjos's avatar
André Anjos committed
61

62

Amir Mohammadi's avatar
Amir Mohammadi committed
63
    def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
64

Amir Mohammadi's avatar
Amir Mohammadi committed
65
        groups = self.convert_names_to_lowlevel(groups,
66
            self.low_level_group_names, self.high_level_group_names)
Amir Mohammadi's avatar
Amir Mohammadi committed
67
        return self._db.model_ids(groups=groups, protocol=protocol)
68

69

Amir Mohammadi's avatar
Amir Mohammadi committed
70 71
    def objects(self, groups=None, protocol=None, purposes=None,
                model_ids=None, **kwargs):
André Anjos's avatar
André Anjos committed
72

Amir Mohammadi's avatar
Amir Mohammadi committed
73
        groups = self.convert_names_to_lowlevel(groups,
74
            self.low_level_group_names, self.high_level_group_names)
Amir Mohammadi's avatar
Amir Mohammadi committed
75
        retval = self._db.objects(groups=groups, protocol=protocol,
76 77
                                  purposes=purposes, model_ids=model_ids,
                                  **kwargs)
78

Amir Mohammadi's avatar
Amir Mohammadi committed
79
        return [File(f) for f in retval]
André Anjos's avatar
André Anjos committed
80

81

Amir Mohammadi's avatar
Amir Mohammadi committed
82 83
    def annotations(self, file):
            return None