Send history of track to predictor
This commit is contained in:
parent
b911caa5af
commit
3091557733
1 changed files with 22 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue