μ½˜ν…μΈ λ‘œ κ±΄λ„ˆλ›°κΈ°

μ°Έμ‘° ultralytics/trackers/basetrack.py

μ°Έκ³ 

이 νŒŒμΌμ€ https://github.com/ultralytics/ ultralytics/blob/main/ ultralytics/trackers/basetrack .pyμ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€. 문제λ₯Ό λ°œκ²¬ν•˜λ©΄ ν’€ λ¦¬ν€˜μŠ€νŠΈ πŸ› οΈ 에 κΈ°μ—¬ν•˜μ—¬ 문제 해결을 λ„μ™€μ£Όμ„Έμš”. κ°μ‚¬ν•©λ‹ˆλ‹€ πŸ™!



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), κΈ€λ Œ 쑰처 (3)