Vai al contenuto

Riferimento per ultralytics/trackers/basetrack.py

Nota

Questo file è disponibile all'indirizzo https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/trackers/basetrack .py. Se noti un problema, contribuisci a risolverlo inviando una Pull Request 🛠️. Grazie 🙏!



ultralytics.trackers.basetrack.TrackState

Classe di enumerazione che rappresenta i possibili stati di un oggetto tracciato.

Attributi:

Nome Tipo Descrizione
New int

Stato in cui l'oggetto viene rilevato di recente.

Tracked int

Stato in cui l'oggetto viene tracciato con successo nei fotogrammi successivi.

Lost int

Stato in cui l'oggetto non viene più tracciato.

Removed int

Stato in cui l'oggetto viene rimosso dal tracciamento.

Codice sorgente in 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 base per il tracciamento degli oggetti, che fornisce attributi e metodi fondamentali.

Attributi:

Nome Tipo Descrizione
_count int

Contatore a livello di classe per gli ID unici delle tracce.

track_id int

Identificatore univoco della traccia.

is_activated bool

Flag che indica se la traccia è attualmente attiva.

state TrackState

Stato attuale della pista.

history OrderedDict

Storia ordinata degli stati della pista.

features list

Elenco delle caratteristiche estratte dall'oggetto per il tracciamento.

curr_feature any

La caratteristica attuale dell'oggetto tracciato.

score float

Il punteggio di fiducia del tracciamento.

start_frame int

Il numero di frame in cui è iniziato il tracciamento.

frame_id int

L'ID del fotogramma più recente elaborato dalla traccia.

time_since_update int

Frammenti trascorsi dall'ultimo aggiornamento.

location tuple

La posizione dell'oggetto nel contesto del tracking multi-camera.

Metodi:

Nome Descrizione
end_frame

Restituisce l'ID dell'ultimo fotogramma in cui l'oggetto è stato tracciato.

next_id

Incrementa e restituisce il prossimo ID traccia globale.

activate

Metodo astratto per attivare il binario.

predict

Metodo astratto per prevedere lo stato successivo del binario.

update

Metodo astratto per aggiornare il tracciato con nuovi dati.

mark_lost

Segna il brano come perso.

mark_removed

Contrassegna il brano come rimosso.

reset_id

Azzera il contatore globale dell'ID traccia.

Codice sorgente in 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

Restituisce l'ID dell'ultimo fotogramma della traccia.

__init__()

Inizializza una nuova traccia con un ID univoco e gli attributi di tracciamento fondamentali.

Codice sorgente in 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)

Metodo astratto per attivare il binario con gli argomenti forniti.

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

mark_lost()

Segna la traccia come persa.

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

mark_removed()

Segna il binario come rimosso.

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

next_id() staticmethod

Incrementa e restituisce il contatore globale dell'ID traccia.

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

predict()

Metodo astratto per prevedere lo stato successivo del binario.

Codice sorgente in ultralytics/trackers/basetrack.py
def predict(self):
    """Abstract method to predict the next state of the track."""
    raise NotImplementedError

reset_id() staticmethod

Azzera il contatore globale dell'ID traccia.

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

update(*args, **kwargs)

Metodo astratto per aggiornare il tracciato con nuove osservazioni.

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





Creato 2023-11-12, Aggiornato 2024-05-08
Autori: Burhan-Q (1), glenn-jocher (3)