Skip to content
Snippets Groups Projects
Commit d1754b93 authored by Ivana CHINGOVSKA's avatar Ivana CHINGOVSKA
Browse files

added methods for querying the face locations bbx

parent 3ccccc84
No related branches found
No related tags found
No related merge requests found
...@@ -156,7 +156,7 @@ class Database(object): ...@@ -156,7 +156,7 @@ class Database(object):
return retval return retval
def faces(self, filenames, directory=None): def facefiles(self, filenames, directory=None):
"""Queries the files containing the face locations for the frames in the videos specified by the input parameter filenames """Queries the files containing the face locations for the frames in the videos specified by the input parameter filenames
Keyword parameters: Keyword parameters:
...@@ -178,11 +178,42 @@ class Database(object): ...@@ -178,11 +178,42 @@ class Database(object):
There is one row for each frame, and not all the frames contain detected faces 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] if directory: return [os.path.join(directory, stem + '.face') for stem in filenames]
return [stem + '.faces' for stem in filenames] return [stem + '.face' for stem in filenames]
def facebbx(self, filenames, directory=None):
def faces_ids(self, ids, directory=None): """Reads 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).
Returns:
A list of numpy.ndarrays containing information about the locatied faces in the videos. Each element in the list corresponds to one input filename. Each row of the numpy.ndarray corresponds for one frame. The five columns of the numpy.ndarray denote:
* Frame number
* Bounding box top-left X coordinate
* Bounding box top-left Y coordinate
* Bounding box width
* Bounding box height
Note that not all the frames contain detected faces.
"""
facefiles = self.facefiles(filenames, directory)
facesbbx = []
for facef in facefiles:
lines = open(facef, "r").readlines()
bbx = numpy.ndarray((len(lines), 5), dtype='int')
lc = 0
for l in lines:
words = l.split()
bbx[lc] = [int(w) for w in words]
lc+=1
facesbbx.append(bbx)
return facesbbx
def facefiles_ids(self, ids, directory=None):
"""Queries the files containing the face locations for the frames in the videos specified by the input parameter ids """Queries the files containing the face locations for the frames in the videos specified by the input parameter ids
Keyword parameters: Keyword parameters:
...@@ -198,9 +229,40 @@ class Database(object): ...@@ -198,9 +229,40 @@ class Database(object):
""" """
if not directory: if not directory:
directory = '' directory = ''
facespaths = self.paths(ids, prefix=directory, suffix='.faces') facespaths = self.paths(ids, prefix=directory, suffix='.face')
return facespaths return facespaths
def facebbx_ids(self, ids, directory=None):
"""Reads 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).
Returns:
A list of numpy.ndarrays containing information about the locatied faces in the videos. Each element in the list corresponds to one input filename. Each row of the numpy.ndarray corresponds for one frame. The five columns of the numpy.ndarray denote:
* Frame number
* Bounding box top-left X coordinate
* Bounding box top-left Y coordinate
* Bounding box width
* Bounding box height
Note that not all the frames contain detected faces.
"""
facefiles = self.facefiles_ids(ids, directory)
facesbbx = []
for facef in facefiles:
lines = open(facef, "r").readlines()
bbx = numpy.ndarray((len(lines), 5), dtype='int')
lc = 0
for l in lines:
words = l.split()
bbx[lc] = [int(w) for w in words]
lc+=1
facesbbx.append(bbx)
return facesbbx
def protocols(self): def protocols(self):
"""Returns the names of all registered protocols""" """Returns the names of all registered protocols"""
......
...@@ -131,8 +131,8 @@ class ReplayDatabaseTest(unittest.TestCase): ...@@ -131,8 +131,8 @@ class ReplayDatabaseTest(unittest.TestCase):
def test13_queryfacefile(self): def test13_queryfacefile(self):
db = Database() db = Database()
self.assertEqual(db.faces(('foo',), directory = 'dir')[0], 'dir/foo.faces',) self.assertEqual(db.facefiles(('foo',), directory = 'dir')[0], 'dir/foo.face',)
def test14_queryfacefile_key(self): def test14_queryfacefile_key(self):
db = Database() db = Database()
self.assertEqual(db.faces_ids(ids=(1,), directory='dir'), db.paths(ids=(1,), prefix='dir', suffix='.faces')) self.assertEqual(db.facefiles_ids(ids=(1,), directory='dir'), db.paths(ids=(1,), prefix='dir', suffix='.face'))
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