Use norfair score history to start object history

This commit is contained in:
Nick Mowen 2023-10-24 07:48:04 -06:00
parent 5e03633248
commit ae650a1128
2 changed files with 8 additions and 5 deletions

View File

@ -105,6 +105,10 @@ class TrackedObject:
def __init__( def __init__(
self, camera, colormap, camera_config: CameraConfig, frame_cache, obj_data self, camera, colormap, camera_config: CameraConfig, frame_cache, obj_data
): ):
# set the score history then remove as it is not part of object state
self.score_history = obj_data["score_history"]
del obj_data["score_history"]
self.obj_data = obj_data self.obj_data = obj_data
self.camera = camera self.camera = camera
self.colormap = colormap self.colormap = colormap
@ -136,11 +140,8 @@ class TrackedObject:
return self.computed_score < threshold return self.computed_score < threshold
def compute_score(self): def compute_score(self):
scores = self.score_history[:] """get median of scores for object."""
# pad with zeros if you dont have at least 3 scores return median(self.score_history)
if len(scores) < 3:
scores += [0.0] * (3 - len(scores))
return median(scores)
def update(self, current_frame_time, obj_data): def update(self, current_frame_time, obj_data):
thumb_update = False thumb_update = False
@ -151,6 +152,7 @@ class TrackedObject:
self.score_history.append(0.0) self.score_history.append(0.0)
else: else:
self.score_history.append(obj_data["score"]) self.score_history.append(obj_data["score"])
# only keep the last 10 scores # only keep the last 10 scores
if len(self.score_history) > 10: if len(self.score_history) > 10:
self.score_history = self.score_history[-10:] self.score_history = self.score_history[-10:]

View File

@ -97,6 +97,7 @@ class NorfairTracker(ObjectTracker):
obj["start_time"] = obj["frame_time"] obj["start_time"] = obj["frame_time"]
obj["motionless_count"] = 0 obj["motionless_count"] = 0
obj["position_changes"] = 0 obj["position_changes"] = 0
obj["score_history"] = [p.data['score'] for p in next((o for o in self.tracker.tracked_objects if o.global_id == track_id)).past_detections]
self.tracked_objects[id] = obj self.tracked_objects[id] = obj
self.disappeared[id] = 0 self.disappeared[id] = 0
self.positions[id] = { self.positions[id] = {