Commit b6a83418 authored by Manuel Günther's avatar Manuel Günther

Switched annotations() function to accept File objects instead of file ids

parent f1249e98
......@@ -75,6 +75,7 @@ class File(Base, bob.db.verification.utils.File):
# for Python
client = relationship("Client", backref=backref("files", order_by=id))
annotation = relationship("Annotation", backref=backref("file"), uselist=False)
def __init__(self, client_id, path, session_id, camera, shot_id):
# call base class constructor
......
......@@ -204,25 +204,20 @@ class Database(bob.db.verification.utils.SQLiteDatabase):
return list(set(retval)) # To remove duplicates
def annotations(self, file_id):
def annotations(self, file):
"""Returns the annotations for the image with the given file id.
Keyword Parameters:
file_id
The id of the File object to retrieve the annotations for.
file
The ``File`` object to retrieve the annotations for.
Returns: the eye annotations as a dictionary {'reye':(y,x), 'leye':(y,x)}.
"""
self.assert_validity()
query = self.query(Annotation).join(File).filter(File.id==file_id)
assert query.count() == 1
annotation = query.first()
# return the annotations as returned by the call function of the Annotation object
return annotation()
return file.annotation()
def protocol_names(self):
......
......@@ -63,7 +63,7 @@ def test_annotations():
# Tests that for all files the annotated eye positions exist and are in correct order
db = bob.db.biosecure.Database()
for f in db.objects():
annotations = db.annotations(f.id)
annotations = db.annotations(f)
assert annotations is not None
assert len(annotations) == 2
assert 'leye' in annotations
......
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