From 3ccccc84448130f6c4a67b0f018bf327beae45fb Mon Sep 17 00:00:00 2001 From: Ivana Chingovska <ivana.chingovska@idiap.ch> Date: Wed, 12 Sep 2012 18:05:14 +0200 Subject: [PATCH] methods for querying the face location files --- xbob/db/replay/query.py | 47 +++++++++++++++++++++++++++++++++++++++++ xbob/db/replay/test.py | 9 ++++++++ 2 files changed, 56 insertions(+) diff --git a/xbob/db/replay/query.py b/xbob/db/replay/query.py index 94f5589..e650ec3 100644 --- a/xbob/db/replay/query.py +++ b/xbob/db/replay/query.py @@ -155,6 +155,53 @@ class Database(object): return retval + + def faces(self, filenames, directory=None): + """Queries the files containing the face locations for the frames in the videos specified by the input parameter filenames + + Keyword parameters: + + filenames + The filenames of the videos. This object should be a python iterable (such as a tuple or list). + + directory + A directory name that will be prepended to the final filepaths returned. The face locations files should be located in this directory + + Returns: + A list of filenames with face locations. The face location files contain the following information, tab delimited: + + * Frame number + * Bounding box top-left X coordinate + * Bounding box top-left Y coordinate + * Bounding box width + * Bounding box height + + There is one row for each frame, and not all the frames contain detected faces + """ + if directory: return [os.path.join(directory, stem + '.faces') for stem in filenames] + return [stem + '.faces' for stem in filenames] + + + def faces_ids(self, ids, directory=None): + """Queries the files containing the face locations for the frames in the videos specified by the input parameter ids + + Keyword parameters: + + ids + The ids of the objects in the database table "file". This object should be a python iterable (such as a tuple or list). + + directory + A directory name that will be prepended to the final filepath returned. The face locations files should be located in this directory + + Returns: + A list of filenames with face locations. For description on the face locations file format, see the documentation for faces() + """ + if not directory: + directory = '' + facespaths = self.paths(ids, prefix=directory, suffix='.faces') + return facespaths + + def protocols(self): """Returns the names of all registered protocols""" diff --git a/xbob/db/replay/test.py b/xbob/db/replay/test.py index 5dd6b6e..ad13189 100644 --- a/xbob/db/replay/test.py +++ b/xbob/db/replay/test.py @@ -127,3 +127,12 @@ class ReplayDatabaseTest(unittest.TestCase): from bob.db.script.dbmanage import main self.assertEqual(main('replay checkfiles --self-test'.split()), 0) + + def test13_queryfacefile(self): + + db = Database() + self.assertEqual(db.faces(('foo',), directory = 'dir')[0], 'dir/foo.faces',) + + def test14_queryfacefile_key(self): + db = Database() + self.assertEqual(db.faces_ids(ids=(1,), directory='dir'), db.paths(ids=(1,), prefix='dir', suffix='.faces')) -- GitLab