
    hh                      P    d Z ddlmZ ddlmZ ddlZ G d d      Z G d d      Zy)	zKModule defines the base classes and structures for object tracking in YOLO.    )OrderedDict)AnyNc                        e Zd ZdZdZdZdZdZy)
TrackStatea  
    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.

    Examples:
        >>> state = TrackState.New
        >>> if state == TrackState.New:
        >>>     print("Object is newly detected.")
    r            N)__name__
__module____qualname____doc__NewTrackedLostRemoved     \/var/www/html/dev/engine/venv/lib/python3.12/site-packages/ultralytics/trackers/basetrack.pyr   r   
   s     CGDGr   r   c                       e Zd ZdZdZd Zedefd       Ze	defd       Z
deddfd	Zdd
ZdededdfdZddZddZe	dd       Zy)	BaseTracka{  
    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.

    Examples:
        Initialize a new track and mark it as lost:
        >>> track = BaseTrack()
        >>> track.mark_lost()
        >>> print(track.state)  # Output: 2 (TrackState.Lost)
    r   c                    d| _         d| _        t        j                  | _        t               | _        g | _        d| _        d| _	        d| _
        d| _        d| _        t        j                  t        j                  f| _        y)zMInitialize a new track with a unique ID and foundational tracking attributes.r   FN)track_idis_activatedr   r   stater   historyfeaturescurr_featurescorestart_frameframe_idtime_since_updatenpinflocationselfs    r   __init__zBaseTrack.__init__E   sf    !^^
"} 
!"(r   returnc                     | j                   S )zDReturn the ID of the most recent frame where the object was tracked.)r    r%   s    r   	end_framezBaseTrack.end_frameS   s     }}r   c                  T    t         xj                  dz  c_        t         j                  S )zIIncrement and return the next unique global track ID for object tracking.r   r   _countr   r   r   next_idzBaseTrack.next_idX   s!     	Ar   argsNc                     t         )z[Activate the track with provided arguments, initializing necessary attributes for tracking.NotImplementedError)r&   r/   s     r   activatezBaseTrack.activate^       !!r   c                     t         )zRPredict the next state of the track based on the current state and tracking model.r1   r%   s    r   predictzBaseTrack.predictb   r4   r   kwargsc                     t         )z`Update the track with new observations and data, modifying its state and attributes accordingly.r1   )r&   r/   r7   s      r   updatezBaseTrack.updatef   r4   r   c                 .    t         j                  | _        y)z@Mark the track as lost by updating its state to TrackState.Lost.N)r   r   r   r%   s    r   	mark_lostzBaseTrack.mark_lostj   s    __
r   c                 .    t         j                  | _        y)zEMark the track as removed by setting its state to TrackState.Removed.N)r   r   r   r%   s    r   mark_removedzBaseTrack.mark_removedn   s    ''
r   c                      dt         _        y)z7Reset the global track ID counter to its initial value.r   Nr,   r   r   r   reset_idzBaseTrack.reset_idr   s     	r   )r(   N)r
   r   r   r   r-   r'   propertyintr*   staticmethodr.   r   r3   r6   r9   r;   r=   r?   r   r   r   r   r       s     D F) 3    S    
"c "d """C "3 "4 "%(  r   r   )	r   collectionsr   typingr   numpyr"   r   r   r   r   r   <module>rF      s'    Q #   ,U Ur   