ensure missing objects are expired even when other object types are in the frame

This commit is contained in:
Blake Blackshear 2020-02-23 07:55:51 -06:00
parent 1d2a41129c
commit a3fa97dd52

View File

@ -49,14 +49,6 @@ class ObjectTracker():
obj['history'] = [entry]
def match_and_update(self, frame_time, new_objects):
if len(new_objects) == 0:
for id in list(self.tracked_objects.keys()):
if self.disappeared[id] >= self.max_disappeared:
self.deregister(id)
else:
self.disappeared[id] += 1
return
# group by name
new_object_groups = defaultdict(lambda: [])
for obj in new_objects:
@ -69,6 +61,18 @@ class ObjectTracker():
'frame_time': frame_time
})
# update any tracked objects with labels that are not
# seen in the current objects and deregister if needed
for id, obj in self.tracked_objects.items():
if not obj['label'] in new_object_groups:
if self.disappeared[id] >= self.max_disappeared:
self.deregister(id)
else:
self.disappeared[id] += 1
if len(new_objects) == 0:
return
# track objects for each label type
for label, group in new_object_groups.items():
current_objects = [o for o in self.tracked_objects.values() if o['label'] == label]