diff --git a/xbob/db/replay/query.py b/xbob/db/replay/query.py index 94f55899272610bd86901e6411de5b341e7a3fd2..e650ec35aeb6ed7bc5fa224c63b3f6a555c10d1f 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 5dd6b6eab916330d73a75b8524de7c26de106b0a..ad131898f901149eb40381fe6331af23c9c7bab5 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'))