abewley / sort

Simple, online, and realtime tracking of multiple objects in a video sequence.
GNU General Public License v3.0
3.82k stars 1.07k forks source link

KalmanTracker 'history' is reset in update #85

Open laclouis5 opened 4 years ago

laclouis5 commented 4 years ago

self.history is reset in KalmanTracker().update() func:

https://github.com/abewley/sort/blob/54e63a7e432491619a48678bda6f05cc3bd12859/sort.py#L109

This removes history when a new measurement is available but save state when only doing prediction.

Also, here in predict():

https://github.com/abewley/sort/blob/54e63a7e432491619a48678bda6f05cc3bd12859/sort.py#L125

Property history is fed with x predicted. But when the tracker is updated with a new measurement, the state x is refined and should replace the old x predicted no?

As predict() is always followed by update() this should look like this:

  def update(self, bbox):
    """
    Updates the state vector with observed bbox.
    """
    self.time_since_update = 0
    self.hits += 1
    self.hit_streak += 1
    self.kf.update(convert_bbox_to_z(bbox))
    self.history[-1] = convert_bbox_to_z(self.kf.x) # history should be previously init with convert_bbox_to_z(bbox) to not be empty

  def predict(self):
    """
    Advances the state vector and returns the predicted bounding box estimate.
    """
    if((self.kf.x[6]+self.kf.x[2])<=0):
      self.kf.x[6] *= 0.0
    self.kf.predict()
    self.age += 1
    if(self.time_since_update>0):
      self.hit_streak = 0
    self.time_since_update += 1
    self.history.append(convert_x_to_bbox(self.kf.x))
    return history[-1]
geraldinedeeplearning commented 8 months ago

As predict() is always followed by update()

Is this correct though? Why is it expected that there will be as many updates as predicts? Then how do we handle missing measurements (when YOLO misses the object in one frame for instance)?

I'm confused about what data we use to update the kalman filter in such case. Wouldn't it make more sense to use the time_since_update for the predict step, namely taking this variable into account when applying the kf.F matrix (the one for the dynamic model). This would allow to call predict once for each frame independently of the YOLO's output and calling update only when we have real information to update