You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
72 lines
1.6 KiB
2 years ago
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||
2 years ago
|
|
||
2 years ago
|
from collections import OrderedDict
|
||
|
|
||
2 years ago
|
import numpy as np
|
||
|
|
||
2 years ago
|
|
||
|
class TrackState:
|
||
2 years ago
|
"""Enumeration of possible object tracking states."""
|
||
|
|
||
2 years ago
|
New = 0
|
||
|
Tracked = 1
|
||
|
Lost = 2
|
||
|
Removed = 3
|
||
|
|
||
|
|
||
|
class BaseTrack:
|
||
2 years ago
|
"""Base class for object tracking, handling basic track attributes and operations."""
|
||
|
|
||
2 years ago
|
_count = 0
|
||
|
|
||
|
track_id = 0
|
||
|
is_activated = False
|
||
|
state = TrackState.New
|
||
|
|
||
|
history = OrderedDict()
|
||
|
features = []
|
||
|
curr_feature = None
|
||
|
score = 0
|
||
|
start_frame = 0
|
||
|
frame_id = 0
|
||
|
time_since_update = 0
|
||
|
|
||
2 years ago
|
# Multi-camera
|
||
2 years ago
|
location = (np.inf, np.inf)
|
||
|
|
||
|
@property
|
||
|
def end_frame(self):
|
||
2 years ago
|
"""Return the last frame ID of the track."""
|
||
2 years ago
|
return self.frame_id
|
||
|
|
||
|
@staticmethod
|
||
|
def next_id():
|
||
2 years ago
|
"""Increment and return the global track ID counter."""
|
||
2 years ago
|
BaseTrack._count += 1
|
||
|
return BaseTrack._count
|
||
|
|
||
|
def activate(self, *args):
|
||
2 years ago
|
"""Activate the track with the provided arguments."""
|
||
2 years ago
|
raise NotImplementedError
|
||
|
|
||
|
def predict(self):
|
||
2 years ago
|
"""Predict the next state of the track."""
|
||
2 years ago
|
raise NotImplementedError
|
||
|
|
||
|
def update(self, *args, **kwargs):
|
||
2 years ago
|
"""Update the track with new observations."""
|
||
2 years ago
|
raise NotImplementedError
|
||
|
|
||
|
def mark_lost(self):
|
||
2 years ago
|
"""Mark the track as lost."""
|
||
2 years ago
|
self.state = TrackState.Lost
|
||
|
|
||
|
def mark_removed(self):
|
||
2 years ago
|
"""Mark the track as removed."""
|
||
2 years ago
|
self.state = TrackState.Removed
|
||
2 years ago
|
|
||
|
@staticmethod
|
||
|
def reset_id():
|
||
2 years ago
|
"""Reset the global track ID counter."""
|
||
2 years ago
|
BaseTrack._count = 0
|