avoid extra tracking work on stationary frames

This commit is contained in:
Blake Blackshear 2022-02-05 08:29:22 -06:00
parent dd1cf4d2ce
commit 7e7d70aa5b
2 changed files with 45 additions and 35 deletions

View File

@ -103,6 +103,10 @@ class ObjectTracker:
self.tracked_objects[id]["position_changes"] += 1
self.tracked_objects[id].update(new_obj)
def update_frame_times(self, frame_time):
for id in self.tracked_objects.keys():
self.tracked_objects[id]["frame_time"] = frame_time
def match_and_update(self, frame_time, new_objects):
# group by name
new_object_groups = defaultdict(lambda: [])

View File

@ -584,6 +584,7 @@ def process_frames(
for obj in object_tracker.tracked_objects.values()
if obj["id"] in stationary_object_ids
]
for region in regions:
detections.extend(
detect(
@ -599,7 +600,7 @@ def process_frames(
#########
# merge objects, check for clipped objects and look again up to 4 times
#########
refining = True
refining = len(regions) > 0
refine_count = 0
while refining and refine_count < 4:
refining = False
@ -654,6 +655,9 @@ def process_frames(
## drop detections that overlap too much
consolidated_detections = []
# if detection was run on this frame, consolidate
if len(regions) > 0:
# group by name
detected_object_groups = defaultdict(lambda: [])
for detection in detections:
@ -689,9 +693,11 @@ def process_frames(
consolidated_detections.append(
sorted_by_area[current_detection_idx]
)
# now that we have refined our detections, we need to track objects
object_tracker.match_and_update(frame_time, consolidated_detections)
# else, just update the frame times for the stationary objects
else:
object_tracker.update_frame_times(frame_time)
# add to the queue if not full
if detected_objects_queue.full():