basetrack.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import numpy as np
  2. from collections import OrderedDict
  3. class TrackState(object):
  4. New = 0
  5. Tracked = 1
  6. Lost = 2
  7. Removed = 3
  8. Replaced = 4
  9. class BaseTrack(object):
  10. _count = 0
  11. track_id = 0
  12. is_activated = False
  13. state = TrackState.New
  14. history = OrderedDict()
  15. features = []
  16. curr_feature = None
  17. score = 0
  18. start_frame = 0
  19. frame_id = 0
  20. time_since_update = 0
  21. # multi-camera
  22. location = (np.inf, np.inf)
  23. @property
  24. def end_frame(self):
  25. return self.frame_id
  26. @staticmethod
  27. def next_id():
  28. BaseTrack._count += 1
  29. return BaseTrack._count
  30. def activate(self, *args):
  31. raise NotImplementedError
  32. def predict(self):
  33. raise NotImplementedError
  34. def update(self, *args, **kwargs):
  35. raise NotImplementedError
  36. def mark_lost(self):
  37. self.state = TrackState.Lost
  38. def mark_removed(self):
  39. self.state = TrackState.Removed
  40. def mark_replaced(self):
  41. self.state = TrackState.Replaced