Skip to content

Reference for ultralytics/trackers/basetrack.py

Note

Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/trackers/basetrack.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!


ultralytics.trackers.basetrack.TrackState

Enumeration of possible object tracking states.

Source code in ultralytics/trackers/basetrack.py
class TrackState:
    """Enumeration of possible object tracking states."""

    New = 0
    Tracked = 1
    Lost = 2
    Removed = 3




ultralytics.trackers.basetrack.BaseTrack

Base class for object tracking, handling basic track attributes and operations.

Source code in ultralytics/trackers/basetrack.py
class BaseTrack:
    """Base class for object tracking, handling basic track attributes and operations."""

    _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

    # Multi-camera
    location = (np.inf, np.inf)

    @property
    def end_frame(self):
        """Return the last frame ID of the track."""
        return self.frame_id

    @staticmethod
    def next_id():
        """Increment and return the global track ID counter."""
        BaseTrack._count += 1
        return BaseTrack._count

    def activate(self, *args):
        """Activate the track with the provided arguments."""
        raise NotImplementedError

    def predict(self):
        """Predict the next state of the track."""
        raise NotImplementedError

    def update(self, *args, **kwargs):
        """Update the track with new observations."""
        raise NotImplementedError

    def mark_lost(self):
        """Mark the track as lost."""
        self.state = TrackState.Lost

    def mark_removed(self):
        """Mark the track as removed."""
        self.state = TrackState.Removed

    @staticmethod
    def reset_id():
        """Reset the global track ID counter."""
        BaseTrack._count = 0

end_frame property

Return the last frame ID of the track.

activate(*args)

Activate the track with the provided arguments.

Source code in ultralytics/trackers/basetrack.py
def activate(self, *args):
    """Activate the track with the provided arguments."""
    raise NotImplementedError

mark_lost()

Mark the track as lost.

Source code in ultralytics/trackers/basetrack.py
def mark_lost(self):
    """Mark the track as lost."""
    self.state = TrackState.Lost

mark_removed()

Mark the track as removed.

Source code in ultralytics/trackers/basetrack.py
def mark_removed(self):
    """Mark the track as removed."""
    self.state = TrackState.Removed

next_id() staticmethod

Increment and return the global track ID counter.

Source code in ultralytics/trackers/basetrack.py
@staticmethod
def next_id():
    """Increment and return the global track ID counter."""
    BaseTrack._count += 1
    return BaseTrack._count

predict()

Predict the next state of the track.

Source code in ultralytics/trackers/basetrack.py
def predict(self):
    """Predict the next state of the track."""
    raise NotImplementedError

reset_id() staticmethod

Reset the global track ID counter.

Source code in ultralytics/trackers/basetrack.py
@staticmethod
def reset_id():
    """Reset the global track ID counter."""
    BaseTrack._count = 0

update(*args, **kwargs)

Update the track with new observations.

Source code in ultralytics/trackers/basetrack.py
def update(self, *args, **kwargs):
    """Update the track with new observations."""
    raise NotImplementedError




Created 2023-07-16, Updated 2023-08-07
Authors: glenn-jocher (5), Laughing-q (1)