§
    >²¸jI  ã                  ó¬   — d dl mZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ d dlmZ erd d	lmZ dd„Zej        fdd„ZdS )é    )Úannotations)ÚTYPE_CHECKINGÚcastN)ÚORIENTED_BOX_COORDINATES)ÚCompactMask)Úobb_polygon_area)ÚOverlapMetricÚbox_iou_batchÚmask_iou_batchÚoriented_box_iou_batch)Úcount_mask_pixels)Ú
DetectionsÚ
detectionsr   Úreturnúnpt.NDArray[np.generic]c                ó<  — | j         �:t          | j         t          ¦  «        r| j         j        S t	          | j         ¦  «        S t
          | j        v rGt          t          t          j
        t          j                 | j        t
                   ¦  «        ¦  «        S | j        S )a%  
    Calculate detection areas using the richest geometry present.

    Selection order:

    1. If ``mask`` is set, return the area of each mask.
    2. Else, if ``data[ORIENTED_BOX_COORDINATES]`` is set, return the area of
       each oriented box.
    3. Otherwise, return the axis-aligned box area.

    Args:
        detections: Detections whose geometry should be measured.

    Returns:
        A 1-D array containing the area of each detection.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.core import Detections
        >>> detections = Detections(
        ...     xyxy=np.array([[0, 0, 2, 3]], dtype=np.float32)
        ... )
        >>> detection_area(detections)  # doctest: +ELLIPSIS
        array([6.], dtype=float32)

        ```
    )ÚmaskÚ
isinstancer   Úarear   r   Údatar   r   ÚnptÚNDArrayÚnpÚnumberÚbox_area)r   s    úx/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/detection/_geometry_dispatch.pyÚdetection_arear      sƒ   € ð: „Ð"Ý�j”o¥{Ñ3Ô3ð 	(Ø”?Ô'Ð'Ý  ¤Ñ1Ô1Ð1Ý :¤?Ð2Ð2ÝÝ•”�RœYÔ'¨¬Õ9QÔ)RÑSÔSñ
ô 
ð 	
ð ÔÐó    Údetections_aÚdetections_bÚoverlap_metricúOverlapMetric | strúnpt.NDArray[np.floating]c                óò  — t          j        |¦  «        }| j        �#|j        �t          | j        |j        |¬¦  «        S t          | j        v r�t          |j        v r‚t          t          t          j	        t          j                 | j        t                   ¦  «        t          t          j	        t          j                 |j        t                   ¦  «        |¬¦  «        S t          | j        |j        |¬¦  «        S )aÐ  
    Calculate pairwise IoU using the richest geometry both operands share.

    Selection order:

    1. If both operands have masks, use mask IoU.
    2. Else, if both operands have oriented-box coordinates, use OBB IoU.
    3. Otherwise, use axis-aligned box IoU.

    This is a **shared**-geometry dispatch, unlike `detection_area`'s
    per-operand dispatch: if the two operands carry different kinds of
    richer geometry (e.g. one has only a mask, the other only oriented-box
    coordinates), neither is used and the axis-aligned box IoU is computed
    instead.

    Args:
        detections_a: First set of detections.
        detections_b: Second set of detections.
        overlap_metric: Metric used to compute the degree of overlap.

    Returns:
        A matrix of pairwise overlaps with shape
            ``(len(detections_a), len(detections_b))``.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.core import Detections
        >>> detections = Detections(
        ...     xyxy=np.array([[0, 0, 2, 2]], dtype=np.float32)
        ... )
        >>> detection_iou(detections, detections)  # doctest: +ELLIPSIS
        array([[1.]], dtype=float32)

        ```
    N)r!   )r	   Ú
from_valuer   r   r   r   r   r   r   r   r   r   r
   Úxyxy)r   r    r!   s      r   Údetection_iour'   ?   sú   € õR #Ô-¨nÑ=Ô=€NØÔÐ$¨Ô):Ð)FÝØÔØÔØ)ð
ñ 
ô 
ð 	
õ 	! LÔ$5Ð5Ð5Ý$¨Ô(9Ð9Ð9å%ÝÝ”�BœIÔ&ØÔ!Õ":Ô;ñô õ Ý”�BœIÔ&ØÔ!Õ":Ô;ñô ð *ð

ñ 

ô 

ð 
	
õ ØÔØÔØ%ðñ ô ð r   )r   r   r   r   )r   r   r    r   r!   r"   r   r#   )Ú
__future__r   Útypingr   r   Únumpyr   Únumpy.typingr   Úsupervision.configr   Ú"supervision.detection.compact_maskr   Ú!supervision.detection.utils.boxesr   Ú'supervision.detection.utils.iou_and_nmsr	   r
   r   r   Ú!supervision.detection.utils.masksr   Úsupervision.detection.corer   r   ÚIOUr'   © r   r   ú<module>r4      s5  ðØ "Ð "Ð "Ð "Ð "Ð "à &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ø Ð Ð Ð Ð Ð à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø :Ð :Ð :Ð :Ð :Ð :Ø >Ð >Ð >Ð >Ð >Ð >ðð ð ð ð ð ð ð ð ð ð ð ð @Ð ?Ð ?Ð ?Ð ?Ð ?àð 6Ø5Ð5Ð5Ð5Ð5Ð5ð%ð %ð %ð %ðV +8Ô*;ðEð Eð Eð Eð Eð Eð Er   