
    h&                     F    S SK Jr  S SKJrJrJr  S SKJr   " S S\5      rg)    )Any)BaseSolutionSolutionAnnotatorSolutionResults)colorsc                   F   ^  \ rS rSrSrS\SS4U 4S jjrS\4S jrSr	U =r
$ )	QueueManager	   a  
Manages queue counting in real-time video streams based on object tracks.

This class extends BaseSolution to provide functionality for tracking and counting objects within a specified
region in video frames.

Attributes:
    counts (int): The current count of objects in the queue.
    rect_color (tuple[int, int, int]): RGB color tuple for drawing the queue region rectangle.
    region_length (int): The number of points defining the queue region.
    track_line (list[tuple[int, int]]): List of track line coordinates.
    track_history (dict[int, list[tuple[int, int]]]): Dictionary storing tracking history for each object.

Methods:
    initialize_region: Initialize the queue region.
    process: Process a single frame for queue management.
    extract_tracks: Extract object tracks from the current frame.
    store_tracking_history: Store the tracking history for an object.
    display_output: Display the processed output.

Examples:
    >>> cap = cv2.VideoCapture("path/to/video.mp4")
    >>> queue_manager = QueueManager(region=[100, 100, 200, 200, 300, 300])
    >>> while cap.isOpened():
    >>>     success, im0 = cap.read()
    >>>     if not success:
    >>>         break
    >>>     results = queue_manager.process(im0)
kwargsreturnNc                    > [         TU ]  " S0 UD6  U R                  5         SU l        SU l        [        U R                  5      U l        g)z`Initialize the QueueManager with parameters for tracking and counting objects in a video stream.r   )   r   r   N )super__init__initialize_regioncounts
rect_colorlenregionregion_length)selfr   	__class__s     `/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/solutions/queue_management.pyr   QueueManager.__init__(   s>    "6" ) -    c           	         SU l         U R                  U5        [        XR                  S9nUR	                  U R
                  U R                  U R                  S-  S9  [        U R                  U R                  U R                  U R                  5       H  u  p4pVUR                  X0R                  XVU5      [        US5      S9  U R                  XC5        U R                   R#                  U/ 5      nSn[%        U5      S:  a  US	   nU R&                  S
:  d  M  U(       d  M  U R(                  R+                  U R-                  U R.                  S   5      5      (       d  M  U =R                   S-  sl         M     UR1                  S[3        U R                   5       3U R
                  U R                  SS9  UR5                  5       n	U R7                  U	5        [9        XR                   [%        U R                  5      S9$ )a  
Process queue management for a single frame of video.

Args:
    im0 (np.ndarray): Input image for processing, typically a frame from a video stream.

Returns:
    (SolutionResults): Contains processed image `im0`, 'queue_count' (int, number of objects in the queue) and
        'total_tracks' (int, total number of tracked objects).

Examples:
    >>> queue_manager = QueueManager()
    >>> frame = cv2.imread("frame.jpg")
    >>> results = queue_manager.process(frame)
r   )
line_width   )reg_ptscolor	thicknessT)labelr!   N      zQueue Counts : )h         )pointsregion_color	txt_color)plot_imqueue_counttotal_tracks)r   extract_tracksr   r   draw_regionr   r   zipboxes	track_idsclssconfs	box_labeladjust_box_labelr   store_tracking_historytrack_historygetr   r   r_scontainsPoint
track_linequeue_counts_displaystrresultdisplay_outputr   )
r   im0	annotatorboxtrack_idclsconfr;   prev_positionr.   s
             r   processQueueManager.process0   s     C %cooF	dkkTXTcTcfgTgh(+DJJ		SWS]S](^$C3+@+@H+U]cdlnr]st''6 !..228R@M !M=!A% -b 1!!Q&==TXX=N=NtzzZ^ZiZijlZmOn=o=oq  )_  	&&c$++./0;;#	 	' 	
 ""$G$ wKKVYZ^ZhZhVijjr   )r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   rL   __static_attributes____classcell__)r   s   @r   r	   r	   	   s/    <. . ./ko /k /kr   r	   N)	typingr   ultralytics.solutions.solutionsr   r   r   ultralytics.utils.plottingr   r	   r   r   r   <module>rX      s#     \ \ -Vk< Vkr   