Ë
    Fêñi  ã                   óF   — d dl mZ d dlmZmZmZ d dlmZ  G d„ de«      Zy)é    )ÚAny)ÚBaseSolutionÚSolutionAnnotatorÚSolutionResults)Úcolorsc                   ó8   ‡ — e Zd ZdZdeddfˆ fd„Zdefd„Zˆ xZS )ÚQueueManagera6  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]): BGR 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        ‰| �  di |¤Ž | j                  «        d| _        d| _        t        | j                  «      | _        y)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     €úh/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/solutions/queue_management.pyr   zQueueManager.__init__'   s>   ø€ ä‰ÑÑ"˜6Ò"Ø×ÑÔ ØˆŒØ)ˆŒÜ  §¡Ó-ˆÕó    c           	      óò  — d| _         | j                  |«       t        || j                  ¬«      }|j	                  | j
                  | j                  | j                  dz  ¬«       t        | j                  | j                  | j                  | j                  «      D ]Ù  \  }}}}|j                  || j                  |||«      t        |d«      ¬«       | j                  ||«       | j                   j#                  |g «      }d}t%        |«      dkD  r|d	   }| j&                  d
k\  sŒŠ|sŒ�| j(                  j+                  | j-                  | j.                  d   «      «      sŒÅ| xj                   dz  c_         ŒÛ |j1                  d| j                   › �| j
                  | j                  d¬«       |j3                  «       }	| j5                  |	«       t7        |	| j                   t%        | j                  «      ¬«      S )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ÚresultÚdisplay_outputr   )
r   Úim0Ú	annotatorÚboxÚtrack_idÚclsÚconfr9   Úprev_positionr,   s
             r   ÚprocesszQueueManager.process/   s¸  € ð ˆŒØ×Ñ˜CÔ Ü% c°d·o±oÔFˆ	Ø×Ñ d§k¡k¸¿¹ÐTX×TcÑTcÐfgÑTgÐÔhä(+¨D¯J©J¸¿¹ÈÏ	É	ÐSW×S]ÑS]Ó(^ò 	!Ñ$ˆC�˜3 à×Ñ ¨4×+@Ñ+@ÀÀdÈHÓ+UÔ]cÐdlÐnrÓ]sÐÔtØ×'Ñ'¨°#Ô6ð !×.Ñ.×2Ñ2°8¸RÓ@ˆMð !ˆMÜ�=Ó! AÒ%Ø -¨bÑ 1�Ø×!Ñ! QÓ&ª=¸T¿X¹X×=NÑ=NÈtÏzÉzÐZ^×ZiÑZiÐjlÑZmÓOnÕ=oØ—’˜qÑ –ð	!ð  	×&Ñ&Ø˜dŸk™k˜]Ð+Ø—;‘;ØŸ™Ø#ð	 	'ô 	
ð ×"Ñ"Ó$ˆØ×Ñ˜GÔ$ô  w¸D¿K¹KÔVYÐZ^×ZhÑZhÓViÔjÐjr   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   rI   Ú__classcell__)r   s   @r   r	   r	   	   s)   ø„ ñð:. ð .¨õ .ð.k˜o÷ .kr   r	   N)	Útypingr   Úultralytics.solutions.solutionsr   r   r   Úultralytics.utils.plottingr   r	   r   r   r   ú<module>rR      s#   ðõ ç \Ñ \Ý -ôTk�<õ Tkr   