basetrack.py 1.1 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. class BaseTrack(object):
  9. def __init__(self, tracker_max_id):
  10. self.tracker_max_id = tracker_max_id
  11. _count = 0
  12. track_id = 0
  13. is_activated = False
  14. state = TrackState.New
  15. history = OrderedDict()
  16. features = []
  17. curr_feature = None
  18. score = 0
  19. start_frame = 0
  20. frame_id = 0
  21. time_since_update = 0
  22. # multi-camera
  23. location = (np.inf, np.inf)
  24. @property
  25. def end_frame(self):
  26. return self.frame_id
  27. def next_id(self):
  28. if BaseTrack._count == self.tracker_max_id:
  29. BaseTrack._count = 0
  30. BaseTrack._count += 1
  31. return BaseTrack._count
  32. def activate(self, *args):
  33. raise NotImplementedError
  34. def predict(self):
  35. raise NotImplementedError
  36. def update(self, *args, **kwargs):
  37. raise NotImplementedError
  38. def mark_lost(self):
  39. self.state = TrackState.Lost
  40. def mark_removed(self):
  41. self.state = TrackState.Removed