Bỏ để qua phần nội dung

Tài liệu tham khảo cho ultralytics/trackers/basetrack.py

Ghi

Tệp này có sẵn tại https://github.com/ultralytics/ultralytics/blob/main/ultralytics/trình theo dõi/basetrack.py. Nếu bạn phát hiện ra một vấn đề, vui lòng giúp khắc phục nó bằng cách đóng góp Yêu cầu 🛠️ kéo. Cảm ơn bạn 🙏 !



ultralytics.trackers.basetrack.TrackState

Lớp liệt kê đại diện cho các trạng thái có thể có của một đối tượng đang được theo dõi.

Thuộc tính:

Tên Kiểu Sự miêu tả
New int

Trạng thái khi đối tượng mới được phát hiện.

Tracked int

Trạng thái khi đối tượng được theo dõi thành công trong các khung tiếp theo.

Lost int

Trạng thái khi đối tượng không còn được theo dõi.

Removed int

Nêu rõ thời điểm đối tượng bị xóa khỏi theo dõi.

Mã nguồn trong 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

Lớp cơ sở để theo dõi đối tượng, cung cấp các thuộc tính và phương thức nền tảng.

Thuộc tính:

Tên Kiểu Sự miêu tả
_count int

Bộ đếm cấp lớp cho ID theo dõi duy nhất.

track_id int

Mã định danh duy nhất cho bản nhạc.

is_activated bool

Gắn cờ cho biết bản nhạc hiện đang hoạt động.

state TrackState

Tình trạng hiện tại của đường đua.

history OrderedDict

Lịch sử theo thứ tự của các trạng thái của đường đua.

features list

Danh sách các tính năng được trích xuất từ đối tượng để theo dõi.

curr_feature any

Tính năng hiện tại của đối tượng đang được theo dõi.

score float

Điểm tin cậy của việc theo dõi.

start_frame int

Số khung nơi bắt đầu theo dõi.

frame_id int

ID khung gần đây nhất được xử lý bởi bản nhạc.

time_since_update int

Khung hình đã trôi qua kể từ lần cập nhật cuối cùng.

location tuple

Vị trí của đối tượng trong bối cảnh theo dõi nhiều camera.

Phương pháp:

Tên Sự miêu tả
end_frame

Trả về ID của khung cuối cùng nơi đối tượng được theo dõi.

next_id

Tăng và trả về ID theo dõi toàn cầu tiếp theo.

activate

Phương pháp trừu tượng để kích hoạt bản nhạc.

predict

Phương pháp trừu tượng để dự đoán trạng thái tiếp theo của bản nhạc.

update

Phương pháp trừu tượng để cập nhật bản nhạc với dữ liệu mới.

mark_lost

Đánh dấu đường đua là bị mất.

mark_removed

Đánh dấu bản nhạc là đã xóa.

reset_id

Đặt lại bộ đếm ID theo dõi chung.

Mã nguồn trong 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

Trả về ID khung cuối cùng của bản nhạc.

__init__()

Khởi tạo một kênh mới với mã nhận dạng duy nhất và các thuộc tính theo dõi nền tảng.

Mã nguồn trong 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)

Phương pháp trừu tượng để kích hoạt bản nhạc với các đối số được cung cấp.

Mã nguồn trong ultralytics/trackers/basetrack.py
def activate(self, *args):
    """Abstract method to activate the track with provided arguments."""
    raise NotImplementedError

mark_lost()

Đánh dấu đường đua là bị mất.

Mã nguồn trong ultralytics/trackers/basetrack.py
def mark_lost(self):
    """Mark the track as lost."""
    self.state = TrackState.Lost

mark_removed()

Đánh dấu bản nhạc là đã xóa.

Mã nguồn trong ultralytics/trackers/basetrack.py
def mark_removed(self):
    """Mark the track as removed."""
    self.state = TrackState.Removed

next_id() staticmethod

Tăng và trả về bộ đếm ID theo dõi toàn cầu.

Mã nguồn trong ultralytics/trackers/basetrack.py
@staticmethod
def next_id():
    """Increment and return the global track ID counter."""
    BaseTrack._count += 1
    return BaseTrack._count

predict()

Phương pháp trừu tượng để dự đoán trạng thái tiếp theo của bản nhạc.

Mã nguồn trong ultralytics/trackers/basetrack.py
def predict(self):
    """Abstract method to predict the next state of the track."""
    raise NotImplementedError

reset_id() staticmethod

Đặt lại bộ đếm ID theo dõi chung.

Mã nguồn trong ultralytics/trackers/basetrack.py
@staticmethod
def reset_id():
    """Reset the global track ID counter."""
    BaseTrack._count = 0

update(*args, **kwargs)

Phương pháp trừu tượng để cập nhật đường đua với những quan sát mới.

Mã nguồn trong ultralytics/trackers/basetrack.py
def update(self, *args, **kwargs):
    """Abstract method to update the track with new observations."""
    raise NotImplementedError





Đã tạo 2023-11-12, Cập nhật 2024-05-08
Tác giả: Burhan-Q (1), glenn-jocher (3)