From 3091557733169702399389ddb220337fb35ea416 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sun, 22 Oct 2023 14:25:01 +0200 Subject: [PATCH] Send history of track to predictor --- trap/tracker.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/trap/tracker.py b/trap/tracker.py index d82672c..b794995 100644 --- a/trap/tracker.py +++ b/trap/tracker.py @@ -40,9 +40,21 @@ DETECTORS = [DETECTOR_RESNET, DETECTOR_YOLOv8] @dataclass class Track: + """A bit of an haphazardous wrapper around the 'real' tracker to provide + a history, with which the predictor can work, as we then can deduce velocity + and acceleration. + """ track_id: str = None history: [Detection]= field(default_factory=lambda: []) + def get_projected_history(self, H): + foot_coordinates = [d.get_foot_coords() for d in self.history] + + if len(foot_coordinates): + return cv2.perspectiveTransform(np.array([foot_coordinates]),H) + return np.array([]) + + @dataclass class Detection: track_id: str @@ -144,27 +156,27 @@ class Tracker: # Store detections into tracklets + projected_coordinates = [] for detection in detections: track = self.tracks[detection.track_id] track.track_id = detection.track_id # for new tracks - track.history.append(detection) + track.history.append(detection) # add to history + # projected_coordinates.append(track.get_projected_history(self.H)) # then get full history + + # TODO: hadle occlusions, and dissappearance # if len(track.history) > 30: # retain 90 tracks for 90 frames # track.history.pop(0) - foot_coordinates = np.array([[t.get_foot_coords()] for t in detections]) - if len(foot_coordinates): - projected_coordinates = cv2.perspectiveTransform(foot_coordinates,self.H) - else: - projected_coordinates = [] - - # print(TEMP_proj_coords) + trajectories = {} - for detection, coords in zip(detections, projected_coordinates): + for detection in detections: tid = str(detection.track_id) + track = self.tracks[detection.track_id] + coords = track.get_projected_history(self.H) # get full history trajectories[tid] = { "id": tid, - "history": [{"x":c[0], "y":c[1]} for c in coords] if not self.config.bypass_prediction else coords.tolist() # already doubles nested, fine for test + "history": [{"x":c[0], "y":c[1]} for c in coords[0]] if not self.config.bypass_prediction else coords[0].tolist() # already doubles nested, fine for test } # logger.info(f"{trajectories}") frame.trajectories = trajectories