a
    yµÿfG  ã                   @   s8   d Z ddlmZ ddlZG dd„ dƒZG dd„ dƒZdS )zKModule defines the base classes and structures for object tracking in YOLO.é    )ÚOrderedDictNc                   @   s    e Zd ZdZdZdZdZdZdS )Ú
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__ÚNewZTrackedÚLostÚRemoved© r   r   úZ/var/www/html/django/DPS/env/lib/python3.9/site-packages/ultralytics/trackers/basetrack.pyr   	   s
   r   c                   @   sh   e Zd ZdZdZdd„ Zedd„ ƒZedd„ ƒZ	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdS )Ú	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                 C   sR   d| _ d| _tj| _tƒ | _g | _d| _d| _	d| _
d| _d| _tjtjf| _dS )zî
        Initializes a new track with a unique ID and foundational tracking attributes.

        Examples:
            Initialize a new track
            >>> track = BaseTrack()
            >>> print(track.track_id)
            0
        r   FN)Ztrack_idZis_activatedr   r   Ústater   ÚhistoryÚfeaturesZcurr_featureZscoreZstart_frameÚframe_idZtime_since_updateÚnpÚinfÚlocation©Úselfr   r   r   Ú__init__D   s    
zBaseTrack.__init__c                 C   s   | j S )zEReturns the ID of the most recent frame where the object was tracked.)r   r   r   r   r   Ú	end_frameZ   s    zBaseTrack.end_framec                   C   s   t  jd7  _t jS )zIIncrement and return the next unique global track ID for object tracking.r   ©r   Ú_countr   r   r   r   Únext_id_   s    zBaseTrack.next_idc                 G   s   t ‚dS )z\Activates the track with provided arguments, initializing necessary attributes for tracking.N©ÚNotImplementedError)r   Úargsr   r   r   Úactivatee   s    zBaseTrack.activatec                 C   s   t ‚dS )zSPredicts the next state of the track based on the current state and tracking model.Nr   r   r   r   r   Úpredicti   s    zBaseTrack.predictc                 O   s   t ‚dS )zaUpdates the track with new observations and data, modifying its state and attributes accordingly.Nr   )r   r!   Úkwargsr   r   r   Úupdatem   s    zBaseTrack.updatec                 C   s   t j| _dS )zAMarks the track as lost by updating its state to TrackState.Lost.N)r   r   r   r   r   r   r   Ú	mark_lostq   s    zBaseTrack.mark_lostc                 C   s   t j| _dS )zFMarks the track as removed by setting its state to TrackState.Removed.N)r   r   r   r   r   r   r   Úmark_removedu   s    zBaseTrack.mark_removedc                   C   s
   dt _dS )z7Reset the global track ID counter to its initial value.r   Nr   r   r   r   r   Úreset_idy   s    zBaseTrack.reset_idN)r   r   r	   r
   r   r   Úpropertyr   Ústaticmethodr   r"   r#   r%   r&   r'   r(   r   r   r   r   r      s   "

r   )r
   Úcollectionsr   Únumpyr   r   r   r   r   r   r   Ú<module>   s   