Skip to content

Référence pour ultralytics/trackers/basetrack.py

Note

Ce fichier est disponible à l'adresse https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/trackers/basetrack .py. Si tu repères un problème, aide à le corriger en contribuant à une Pull Request 🛠️. Merci 🙏 !



ultralytics.trackers.basetrack.TrackState

Classe d'énumération représentant les états possibles d'un objet suivi.

Attributs :

Nom Type Description
New int

État lorsque l'objet est nouvellement détecté.

Tracked int

État lorsque l'objet est suivi avec succès dans les images suivantes.

Lost int

État dans lequel l'objet n'est plus suivi.

Removed int

État lorsque l'objet est retiré du suivi.

Code source dans ultralytics/trackers/basetrack.py
class TrackState:
    """
    Enumeration class representing the possible states of an object being tracked.

    Attributes:
        New (int): State when the object is newly detected.
        Tracked (int): State when the object is successfully tracked in subsequent frames.
        Lost (int): State when the object is no longer tracked.
        Removed (int): State when the object is removed from tracking.
    """

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



ultralytics.trackers.basetrack.BaseTrack

Classe de base pour le suivi des objets, fournissant des attributs et des méthodes fondamentales.

Attributs :

Nom Type Description
_count int

Compteur de niveau de classe pour les identifiants de piste uniques.

track_id int

Identifiant unique pour la piste.

is_activated bool

Drapeau indiquant si la piste est actuellement active.

state TrackState

État actuel de la piste.

history OrderedDict

Histoire ordonnée des états de la piste.

features list

Liste des caractéristiques extraites de l'objet pour le suivi.

curr_feature any

La caractéristique actuelle de l'objet suivi.

score float

Le score de confiance du suivi.

start_frame int

Le numéro de cadre où le suivi a commencé.

frame_id int

L'identifiant de la trame la plus récente traitée par la piste.

time_since_update int

Frames passées depuis la dernière mise à jour.

location tuple

L'emplacement de l'objet dans le cadre d'un suivi multi-caméras.

MĂ©thodes :

Nom Description
end_frame

Renvoie l'ID de la dernière image où l'objet a été suivi.

next_id

Incrémente et renvoie l'identifiant de piste global suivant.

activate

MĂ©thode abstraite pour activer la piste.

predict

Méthode abstraite pour prédire le prochain état de la piste.

update

Méthode abstraite pour mettre à jour la piste avec de nouvelles données.

mark_lost

Marque la piste comme perdue.

mark_removed

Marque la piste comme étant supprimée.

reset_id

RĂ©initialise le compteur global d'identification de la piste.

Code source dans ultralytics/trackers/basetrack.py
class BaseTrack:
    """
    Base class for object tracking, providing foundational attributes and methods.

    Attributes:
        _count (int): Class-level counter for unique track IDs.
        track_id (int): Unique identifier for the track.
        is_activated (bool): Flag indicating whether the track is currently active.
        state (TrackState): Current state of the track.
        history (OrderedDict): Ordered history of the track's states.
        features (list): List of features extracted from the object for tracking.
        curr_feature (any): The current feature of the object being tracked.
        score (float): The confidence score of the tracking.
        start_frame (int): The frame number where tracking started.
        frame_id (int): The most recent frame ID processed by the track.
        time_since_update (int): Frames passed since the last update.
        location (tuple): The location of the object in the context of multi-camera tracking.

    Methods:
        end_frame: Returns the ID of the last frame where the object was tracked.
        next_id: Increments and returns the next global track ID.
        activate: Abstract method to activate the track.
        predict: Abstract method to predict the next state of the track.
        update: Abstract method to update the track with new data.
        mark_lost: Marks the track as lost.
        mark_removed: Marks the track as removed.
        reset_id: Resets the global track ID counter.
    """

    _count = 0

    def __init__(self):
        """Initializes a new track with unique ID and foundational tracking attributes."""
        self.track_id = 0
        self.is_activated = False
        self.state = TrackState.New
        self.history = OrderedDict()
        self.features = []
        self.curr_feature = None
        self.score = 0
        self.start_frame = 0
        self.frame_id = 0
        self.time_since_update = 0
        self.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):
        """Abstract method to activate the track with provided arguments."""
        raise NotImplementedError

    def predict(self):
        """Abstract method to predict the next state of the track."""
        raise NotImplementedError

    def update(self, *args, **kwargs):
        """Abstract method to 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

Renvoie l'identifiant de la dernière image de la piste.

__init__()

Initialise une nouvelle piste avec un identifiant unique et des attributs de suivi fondamentaux.

Code source dans ultralytics/trackers/basetrack.py
def __init__(self):
    """Initializes a new track with unique ID and foundational tracking attributes."""
    self.track_id = 0
    self.is_activated = False
    self.state = TrackState.New
    self.history = OrderedDict()
    self.features = []
    self.curr_feature = None
    self.score = 0
    self.start_frame = 0
    self.frame_id = 0
    self.time_since_update = 0
    self.location = (np.inf, np.inf)

activate(*args)

MĂ©thode abstraite pour activer la piste avec les arguments fournis.

Code source dans ultralytics/trackers/basetrack.py
def activate(self, *args):
    """Abstract method to activate the track with provided arguments."""
    raise NotImplementedError

mark_lost()

Marque la piste comme perdue.

Code source dans ultralytics/trackers/basetrack.py
def mark_lost(self):
    """Mark the track as lost."""
    self.state = TrackState.Lost

mark_removed()

Marque la piste comme étant enlevée.

Code source dans ultralytics/trackers/basetrack.py
def mark_removed(self):
    """Mark the track as removed."""
    self.state = TrackState.Removed

next_id() staticmethod

Incrémente et renvoie le compteur global d'identification de la piste.

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

predict()

Méthode abstraite pour prédire le prochain état de la piste.

Code source dans ultralytics/trackers/basetrack.py
def predict(self):
    """Abstract method to predict the next state of the track."""
    raise NotImplementedError

reset_id() staticmethod

RĂ©initialise le compteur global d'identification de la piste.

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

update(*args, **kwargs)

MĂ©thode abstraite pour mettre Ă  jour la piste avec de nouvelles observations.

Code source dans ultralytics/trackers/basetrack.py
def update(self, *args, **kwargs):
    """Abstract method to update the track with new observations."""
    raise NotImplementedError





Créé le 2023-11-12, Mis à jour le 2024-05-08
Auteurs : Burhan-Q (1), glenn-jocher (3)