コンテンツへスキップ

参考 ultralytics/trackers/basetrack.py

このファイルはhttps://github.com/ultralytics/ultralytics/blob/main/ ultralytics/trackers/basetrack .py にあります。もし問題を発見したら、Pull Request🛠️ を投稿して修正にご協力ください。ありがとうございました!



ultralytics.trackers.basetrack.TrackState

追跡されるオブジェクトの可能な状態を表す列挙クラス。

属性:

名称 タイプ 説明
New int

オブジェクトが新たに検出されたときの状態。

Tracked int

後続フレームでオブジェクトの追跡に成功したときの状態。

Lost int

オブジェクトが追跡されなくなったときの状態。

Removed int

オブジェクトがトラッキングから外されたときの状態。

ソースコード 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

オブジェクト追跡の基本クラスで、基本となる属性とメソッドを提供します。

属性:

名称 タイプ 説明
_count int

ユニークなトラックIDのクラスレベルのカウンター。

track_id int

トラック固有の識別子。

is_activated bool

トラックが現在アクティブかどうかを示すフラグ。

state TrackState

コースの現状

history OrderedDict

トラック状態の履歴の順序。

features list

トラッキングのためにオブジェクトから抽出された特徴のリスト。

curr_feature any

追跡対象の現在の特徴。

score float

トラッキングの信頼度。

start_frame int

トラッキングが開始されたフレーム番号。

frame_id int

トラックが処理した最新のフレームID。

time_since_update int

前回の更新から経過したフレーム数。

location tuple

マルチカメラトラッキングにおけるオブジェクトの位置。

方法:

名称 説明
end_frame

オブジェクトが追跡された最後のフレームの ID を返します。

next_id

次のグローバルトラックIDをインクリメントして返す。

activate

トラックをアクティブにする抽象的なメソッド。

predict

トラックの次の状態を予測する抽象的なメソッド。

update

新しいデータでトラックを更新する抽象的なメソッド。

mark_lost

失われたトラックとしてマークを付ける。

mark_removed

削除されたトラックをマークする。

reset_id

グローバルトラックIDカウンターをリセットする。

ソースコード 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

トラックの最後のフレームIDを返す。

__init__()

一意のIDと基本トラッキング属性を持つ新しいトラックを初期化します。

ソースコード 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)

与えられた引数でトラックをアクティブにする抽象メソッド。

ソースコード ultralytics/trackers/basetrack.py
def activate(self, *args):
    """Abstract method to activate the track with provided arguments."""
    raise NotImplementedError

mark_lost()

トラックをロストとマークする。

ソースコード ultralytics/trackers/basetrack.py
def mark_lost(self):
    """Mark the track as lost."""
    self.state = TrackState.Lost

mark_removed()

トラックを取り外したことを示す印をつける。

ソースコード ultralytics/trackers/basetrack.py
def mark_removed(self):
    """Mark the track as removed."""
    self.state = TrackState.Removed

next_id() staticmethod

グローバルトラックIDカウンターをインクリメントして返す。

ソースコード ultralytics/trackers/basetrack.py
@staticmethod
def next_id():
    """Increment and return the global track ID counter."""
    BaseTrack._count += 1
    return BaseTrack._count

predict()

トラックの次の状態を予測する抽象的なメソッド。

ソースコード ultralytics/trackers/basetrack.py
def predict(self):
    """Abstract method to predict the next state of the track."""
    raise NotImplementedError

reset_id() staticmethod

グローバルトラックIDカウンターをリセットする。

ソースコード ultralytics/trackers/basetrack.py
@staticmethod
def reset_id():
    """Reset the global track ID counter."""
    BaseTrack._count = 0

update(*args, **kwargs)

新しいオブザベーションでトラックを更新する抽象的なメソッド。

ソースコード ultralytics/trackers/basetrack.py
def update(self, *args, **kwargs):
    """Abstract method to update the track with new observations."""
    raise NotImplementedError





作成 2023-11-12 更新 2024-05-08
著者Burhan-Q(1),glenn-jocher(3)