Commit f0e6feee authored by André Anjos's avatar André Anjos 💬
Browse files

[driver] Re-generate all bounding-boxes for all videos as part of the metadata to keep

parent 40774806
......@@ -80,20 +80,15 @@ def create_meta(args):
continue
try:
print "Creating meta data for `%s'..." % obj.make_path()
bb = obj.run_face_detector(args.directory, max_frames=1)[0]
bb = obj.run_face_detector(args.directory)
hr = obj.estimate_heartrate_in_bpm(args.directory)
if bb and hr:
outdir = os.path.dirname(output)
if not os.path.exists(outdir): os.makedirs(outdir)
h5 = bob.io.base.HDF5File(output, 'w')
h5.create_group('face_detector')
h5.cd('face_detector')
h5.set('topleft_x', bb.topleft.x)
h5.set('topleft_y', bb.topleft.y)
h5.set('width', bb.size.x)
h5.set('height', bb.size.y)
h5.set_attribute('quality', bb.quality)
h5.cd('..')
bb_save = [(bb[k].topleft.y, bb[k].topleft.x, bb[k].size.y, bb[k].size.x) for k in sorted(bb.keys())]
h5.set('face_detector', numpy.array(bb_save))
h5.set_attribute('quality', numpy.array([bb[k].quality for k in sorted(bb.keys())]), '/face_detector')
h5.set('heartrate', hr)
h5.set_attribute('units', 'beats-per-minute', 'heartrate')
h5.close()
......
......@@ -114,8 +114,8 @@ class File(object):
return detections
def load_face_detection(self):
"""Loads the face detection from locally stored files if they exist, fails
def load_face_detections(self):
"""Loads the face detections from locally stored files if they exist, fails
gracefully otherwise, returning `None`"""
data_dir = pkg_resources.resource_filename(__name__, 'data')
......@@ -123,12 +123,9 @@ class File(object):
if os.path.exists(path):
f = bob.io.base.HDF5File(path)
f.cd('face_detector')
return BoundingBox(
Point(f.get('topleft_y'), f.get('topleft_x')),
Point(f.get('height'), f.get('width')),
f.get_attribute('quality'),
)
bb = f.get('face_detector')
qu = f.get_attribute('quality', '/face_detector')
return [BoundingBox(Point(k[0], k[1]), Point(k[2], k[3]), q) for k,q in zip(bb, qu)]
return None
......
......@@ -95,8 +95,8 @@ class HCITaggingTest(unittest.TestCase):
for obj in self.db.objects()[:3]:
detection = obj.load_face_detection()
assert detection
detections = obj.load_face_detections()
assert detections
hr = obj.load_heart_rate_in_bpm()
assert hr
......
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