§
    >²¸jÐ ã                  óê  — d dl mZ d dlZd dlmZmZ 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  G d
„ de¦  «        Z G d„ de¦  «        Zdbd„Zdcd„Zej        fddd„Zej        fded!„Zdfd&„Zdgd(„Z dhd)„Z!did-„Z"ej        fdjd/„Z#ej        fdkd3„Z$ej        fdld5„Z%ej        d6fdmd:„Z&d;ej        d<fdndA„Z'd;ej        d<fdodC„Z(dpdE„Z)dqdH„Z*drdI„Z+dsdK„Z,d;ej        fdtdL„Z-d;ej        fdudM„Z.d;ej        fdvdO„Z/	 dwej        d<dPœdxdR„Z0dydV„Z1d;ej        fdzdW„Z2d;ej        fdzdX„Z3d{d[„Z4d;ej        fd|d\„Z5d;ej        fd|d]„Z6d;ej        fd}d_„Z7d;ej        fd~d`„Z8d;ej        fd~da„Z9dS )é    )ÚannotationsN)ÚCallableÚSequence)ÚEnum)ÚAnyÚcast)Ú_cv2)ÚCompactMask)Úmask_to_xyxy)Úwarn_deprecatedc                  óN   — e Zd ZdZdZdZdZedd„¦   «         Zedd
„¦   «         Z	dS )ÚOverlapFiltera;  
    Enum specifying the strategy for filtering overlapping detections.

    Attributes:
        NONE: Do not filter detections based on overlap.
        NON_MAX_SUPPRESSION: Filter detections using non-max suppression. This means,
            detections that overlap by more than a set threshold will be discarded,
            except for the one with the highest confidence.
        NON_MAX_MERGE: Merge detections with non-max merging. This means,
            detections that overlap by more than a set threshold will be merged
            into a single detection.
    ÚnoneÚnon_max_suppressionÚnon_max_mergeÚreturnú	list[str]c                ó>   — t          t          d„ | ¦  «        ¦  «        S )Nc                ó   — | j         S ©N©Úvalue©Úmembers    úw/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/detection/utils/iou_and_nms.pyú<lambda>z$OverlapFilter.list.<locals>.<lambda>%   ó   €  v¤|€ ó    ©ÚlistÚmap©Úclss    r   r    zOverlapFilter.list#   ó   € å•CÐ3Ð3°SÑ9Ô9Ñ:Ô:Ð:r   r   úOverlapFilter | strc                óJ  — t          || ¦  «        r|S t          |t          ¦  «        rU|                     ¦   «         }	  | |¦  «        S # t          $ r( t          d|› d|                      ¦   «         › �¦  «        ‚w xY wt          dt          |¦  «        › d| j        › d�¦  «        ‚©NzInvalid value: z. Must be one of zInvalid value type: z. Must be an instance of z or str.)Ú
isinstanceÚstrÚlowerÚ
ValueErrorr    ÚtypeÚ__name__©r#   r   s     r   Ú
from_valuezOverlapFilter.from_value'   óÐ   € å�e˜SÑ!Ô!ð 	ØˆLÝ�e�SÑ!Ô!ð 	YØ—K’K‘M”MˆEðYØ�s˜5‘z”zÐ!øÝð Yð Yð YÝ Ð!W°5Ð!WÐ!WÈ3Ï8Ê8É:Ì:Ð!WÐ!WÑXÔXÐXðYøøøåð&¥4¨¡;¤;ð &ð &ØŒ|ð&ð &ð &ñ
ô 
ð 	
ó   ½
A Á2A:N©r   r   )r   r%   r   r   )
r-   Ú
__module__Ú__qualname__Ú__doc__ÚNONEÚNON_MAX_SUPPRESSIONÚNON_MAX_MERGEÚclassmethodr    r/   © r   r   r   r      sn   € € € € € ðð ð €DØ/ÐØ#€Màð;ð ;ð ;ñ „[ð;ð ð
ð 
ð 
ñ „[ð
ð 
ð 
r   r   c                  óJ   — e Zd ZdZdZdZedd„¦   «         Zedd	„¦   «         Zd
S )ÚOverlapMetrica  
    Enum specifying the metric for measuring overlap between detections.

    Attributes:
        IOU: Intersection over Union. A region-overlap metric that compares
            two shapes (usually bounding boxes or masks) by normalising the
            shared area with the area of their union.
        IOS: Intersection over Smaller, a region-overlap metric that compares
            two shapes (usually bounding boxes or masks) by normalising the
            shared area with the smaller of the two shapes.
    ÚIOUÚIOSr   r   c                ó>   — t          t          d„ | ¦  «        ¦  «        S )Nc                ó   — | j         S r   r   r   s    r   r   z$OverlapMetric.list.<locals>.<lambda>I   r   r   r   r"   s    r   r    zOverlapMetric.listG   r$   r   r   úOverlapMetric | strc                óJ  — t          || ¦  «        r|S t          |t          ¦  «        rU|                     ¦   «         }	  | |¦  «        S # t          $ r( t          d|› d|                      ¦   «         › �¦  «        ‚w xY wt          dt          |¦  «        › d| j        › d�¦  «        ‚r'   )r(   r)   Úupperr+   r    r,   r-   r.   s     r   r/   zOverlapMetric.from_valueK   r0   r1   Nr2   )r   rA   r   r<   )	r-   r3   r4   r5   r=   r>   r9   r    r/   r:   r   r   r<   r<   7   sh   € € € € € ð
ð 
ð €CØ
€Càð;ð ;ð ;ñ „[ð;ð ð
ð 
ð 
ñ „[ð
ð 
ð 
r   r<   Úiou_thresholdÚfloatr   ÚNonec                óJ   — d| cxk    rdk    sn t          d| › d�¦  «        ‚dS )z@Raise `ValueError` when an IoU threshold falls outside `[0, 1]`.r   é   zBValue of `iou_threshold` must be in the closed range from 0 to 1, ú given.N©r+   )rD   s    r   Ú_validate_iou_thresholdrK   [   sR   € à�Ð"Ð"Ò"Ð" Ò"Ð"Ð"Ð"Ýð&Øð&ð &ð &ñ
ô 
ð 	
ð #Ð"r   rC   ú	np.numberr*   c                ó¶   — t          t          j        | ¦  «                             ¦   «         t          j        |¦  «                             ¦   «         z
  ¦  «        S )zCSubtract box coordinates without overflowing integer NumPy scalars.)rE   ÚnpÚasarrayÚitem)rC   r*   s     r   Ú_coordinate_differencerQ   d   sA   € å•”˜EÑ"Ô"×'Ò'Ñ)Ô)­B¬J°uÑ,=Ô,=×,BÒ,BÑ,DÔ,DÑDÑEÔEÐEr   Úbox_trueú$list[float] | npt.NDArray[np.number]Úbox_detectionÚoverlap_metricrA   c                ód  — t                                |¦  «        }t          j        | ¦  «        }t          j        |¦  «        }t          j        |¦  «        st          j        |¦  «        rt          d¦  «        ‚|\  }}}}|\  }	}
}}t          ||	¦  «        }t          ||
¦  «        }t          ||¦  «        }t          ||¦  «        }t          dt          ||¦  «        ¦  «        }t          dt          ||¦  «        ¦  «        }||z  }t          ||¦  «        t          ||¦  «        z  }t          ||	¦  «        t          ||
¦  «        z  }|t           j	        k    r	||z   |z
  }n4|t           j
        k    rt          ||¦  «        }nt          d|› d�¦  «        ‚|dk    rdS t          ||z  ¦  «        S )a  
    Compute overlap metric between two bounding boxes.

    Supports standard IOU (intersection-over-union) and IOS
    (intersection-over-smaller-area) metrics. Returns the overlap value in range
    `[0, 1]`. Integer coordinates are subtracted before conversion to floating
    point so large origins remain precise while area products avoid integer overflow.

    Args:
        box_true: Ground truth box in format
          `(x_min, y_min, x_max, y_max)`.
        box_detection: Detected box in format
          `(x_min, y_min, x_max, y_max)`.
        overlap_metric: Overlap type.
          Use `OverlapMetric.IOU` for IOU or
          `OverlapMetric.IOS` for IOS. Defaults to `OverlapMetric.IOU`.

    Returns:
        Overlap value between boxes in `[0, 1]`.

    Raises:
        TypeError: If either box contains complex coordinates.
        ValueError: If `overlap_metric` is not IOU or IOS.

    Examples:
        ```pycon
        >>> import supervision as sv
        >>> box_true = [100, 100, 200, 200]
        >>> box_detection = [150, 150, 250, 250]
        >>> sv.box_iou(box_true, box_detection, overlap_metric=sv.OverlapMetric.IOU)
        0.142857...
        >>> sv.box_iou(box_true, box_detection, overlap_metric=sv.OverlapMetric.IOS)
        0.25

        ```
    z#box coordinates must be real-valuedç        úoverlap_metric ú5 is not supported, only 'IOU' and 'IOS' are supported)r<   r/   rN   rO   ÚiscomplexobjÚ	TypeErrorÚmaxÚminrQ   r=   r>   r+   rE   )rR   rT   rU   Úbox_true_arrayÚbox_detection_arrayÚ
x_min_trueÚ
y_min_trueÚ
x_max_trueÚ
y_max_trueÚ	x_min_detÚ	y_min_detÚ	x_max_detÚ	y_max_detÚx_min_interÚy_min_interÚx_max_interÚy_max_interÚinter_wÚinter_hÚ
area_interÚ	area_trueÚarea_detÚ	area_norms                          r   Úbox_iourr   i   sÝ  € õR #×-Ò-¨nÑ=Ô=€NÝ”Z Ñ)Ô)€NÝœ* ]Ñ3Ô3ÐÝ	„�~Ñ&Ô&ð ?­"¬/Ð:MÑ*NÔ*Nð ?ÝÐ=Ñ>Ô>Ð>à5CÑ2€J�
˜J¨
Ø1DÑ.€Iˆy˜) Yå�j )Ñ,Ô,€KÝ�j )Ñ,Ô,€KÝ�j )Ñ,Ô,€KÝ�j )Ñ,Ô,€Kå�#Õ-¨k¸;ÑGÔGÑHÔH€GÝ�#Õ-¨k¸;ÑGÔGÑHÔH€Gà˜7Ñ"€Jå& z°:Ñ>Ô>ÕAWØ�JñBô Bñ €Iõ & i°Ñ;Ô;Õ>TØ�9ñ?ô ?ñ €Hð �Ô*Ò*Ð*Ø Ñ(¨:Ñ5ˆ	ˆ	Ø	�=Ô,Ò	,Ð	,Ý˜	 8Ñ,Ô,ˆ	ˆ	åð1˜nð 1ð 1ð 1ñ
ô 
ð 	
ð
 �CÒÐØˆså�˜iÑ'Ñ(Ô(Ð(r   Ú
boxes_trueúnpt.NDArray[np.number]Úboxes_detectionúnpt.NDArray[np.float32]c                ó0  — t                                |¦  «        }| j                             t          j        ¦  «        \  }}}}|j                             t          j        ¦  «        \  }}}	}
| j        d         |j        d         }}|dk    s|dk    rJt          t          j	        t          j
                 t	          j        ||ft          j
        ¬¦  «        ¦  «        S t	          j        ||ft          j        ¬¦  «        }t	          j        |¦  «        }t	          j        |¦  «        }t	          j        |¦  «        }t	          j        |dd…df         |ddd…f         |¬¦  «         t	          j        |dd…df         |	ddd…f         |¬¦  «         t	          j        |dd…df         |ddd…f         |¬¦  «         t	          j        |dd…df         |
ddd…f         |¬¦  «         t	          j        |||¬¦  «         t	          j        |||¬¦  «         t	          j        |dd|¬¦  «         t	          j        |dd|¬¦  «         ||z  }||z
  ||z
  z  }|	|z
  |
|z
  z  }|t           j        k    r|dd…df         |ddd…f         z   |z
  }nM|t           j        k    r*t	          j        |dd…df         |ddd…f         ¦  «        }nt'          d|› d�¦  «        ‚t	          j        |t          j
        ¬¦  «        }t	          j        ||||dk    ¬¦  «         |S )	a/  
    Compute pairwise overlap scores between batches of bounding boxes.

    Supports standard IOU (intersection-over-union) and IOS
    (intersection-over-smaller-area) metrics for all `boxes_true` and
    `boxes_detection` pairs. Returns a matrix of overlap values in range
    `[0, 1]`, matching each box from the first batch to each from the second.

    Args:
        boxes_true: Array of reference boxes in
            shape `(N, 4)` as `(x_min, y_min, x_max, y_max)`.
        boxes_detection: Array of detected boxes in
            shape `(M, 4)` as `(x_min, y_min, x_max, y_max)`.
        overlap_metric: Overlap type.
            Use `OverlapMetric.IOU` for intersection-over-union,
            `OverlapMetric.IOS` for intersection-over-smaller-area.
            Defaults to `OverlapMetric.IOU`.

    Returns:
        Overlap matrix of shape `(N, M)`, where entry
            `[i, j]` is the overlap between `boxes_true[i]` and
            `boxes_detection[j]`.

    Raises:
        ValueError: If `overlap_metric` is not IOU or IOS.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> boxes_true = np.array([
        ...     [100, 100, 200, 200],
        ...     [300, 300, 400, 400]
        ... ])
        >>> boxes_detection = np.array([
        ...     [150, 150, 250, 250],
        ...     [320, 320, 420, 420]
        ... ])
        >>> sv.box_iou_batch(
        ...     boxes_true, boxes_detection, overlap_metric=sv.OverlapMetric.IOU
        ... )
        array([[0.14285..., 0.        ],
               [0.        , 0.47058...]], dtype=float32)
        >>> sv.box_iou_batch(
        ...     boxes_true, boxes_detection, overlap_metric=sv.OverlapMetric.IOS
        ... )
        array([[0.25, 0.  ],
               [0.  , 0.64]], dtype=float32)

        ```
    r   ©ÚdtypeN©ÚoutrW   rX   rY   ©r{   Úwhere)r<   r/   ÚTÚastyperN   Úfloat64Úshaper   ÚnptÚNDArrayÚfloat32ÚemptyÚ
empty_likeÚmaximumÚminimumÚsubtractÚclipr=   r>   r+   Ú
zeros_likeÚdivide)rs   ru   rU   r`   ra   rb   rc   rd   re   rf   rg   Ú
count_trueÚ	count_detrh   rj   ri   rk   rn   ro   rp   rq   r{   s                         r   Úbox_iou_batchr�   ¼   s4  € õp #×-Ò-¨nÑ=Ô=€Nð 6@´\×5HÒ5HÍÌÑ5TÔ5TÑ2€J�
˜J¨
Ø1@Ô1B×1IÒ1IÍ"Ì*Ñ1UÔ1UÑ.€Iˆy˜) YØ&Ô,¨QÔ/°Ô1FÀqÔ1I�	€Jà�Q‚€˜) qš.˜.ÝÝŒK�œ
Ô#¥R¤X¨z¸9Ð.EÍRÌZÐ%XÑ%XÔ%Xñ
ô 
ð 	
õ ”(˜J¨	Ð2½"¼*ÐEÑEÔE€KÝ”- Ñ,Ô,€KÝ”- Ñ,Ô,€KÝ”- Ñ,Ô,€Kå„Jˆz˜!˜!˜!˜T˜'Ô" I¨d°A°A°A¨gÔ$6¸KÐHÑHÔHÐHÝ„Jˆz˜!˜!˜!˜T˜'Ô" I¨d°A°A°A¨gÔ$6¸KÐHÑHÔHÐHÝ„Jˆz˜!˜!˜!˜T˜'Ô" I¨d°A°A°A¨gÔ$6¸KÐHÑHÔHÐHÝ„Jˆz˜!˜!˜!˜T˜'Ô" I¨d°A°A°A¨gÔ$6¸KÐHÑHÔHÐHõ „K�˜[¨kÐ:Ñ:Ô:Ð:Ý„K�˜[¨kÐ:Ñ:Ô:Ð:Ý„GˆK˜˜d¨Ð4Ñ4Ô4Ð4Ý„GˆK˜˜d¨Ð4Ñ4Ô4Ð4à˜{Ñ*€Jà˜jÑ(¨Z¸*Ñ-DÑE€IØ˜IÑ%¨)°iÑ*?Ñ@€Hà�Ô*Ò*Ð*Ø˜a˜a˜a ˜gÔ&¨°$¸¸¸°'Ô):Ñ:¸ZÑGˆ	ˆ	Ø	�=Ô,Ò	,Ð	,Ý”J˜y¨¨¨¨D¨Ô1°8¸DÀ!À!À!¸GÔ3DÑEÔEˆ	ˆ	åð1˜nð 1ð 1ð 1ñ
ô 
ð 	
õ
 $&¤=°Å2Ä:Ð#NÑ#NÔ#N€CÝ„Iˆj˜)¨°IÀ²MÐBÑBÔBÐBØ€Jr   úSequence[Sequence[float]]Úis_crowdúSequence[bool]únpt.NDArray[np.float64]c           	     óÀ  — t          |¦  «        t          | ¦  «        k    r0t          dt          |¦  «        › dt          | ¦  «        › d�¦  «        ‚t          |¦  «        dk    st          | ¦  «        dk    r<t          j        t          |¦  «        t          | ¦  «        ft          j        ¬¦  «        S t          j        d¦  «        }t          j        | t          j        ¬¦  «        }t          j        |t          j        ¬¦  «        }t          j        |t          ¬¦  «        }|dd…df         |dd…df         z   |dd…df         |dd…d	f         z   }}|dd…df         |dd…df         z   |dd…df         |dd…d	f         z   }
}	t          j        |dd…df         dd…df         |dd…df         ddd…f         ¦  «        }t          j        |dd…df         dd…df         |dd…df         ddd…f         ¦  «        }t          j	        |	dd…df         |ddd…f         ¦  «        }t          j	        |
dd…df         |ddd…f         ¦  «        }t          j        ||z
  d
¦  «        t          j        ||z
  d
¦  «        z  }t          j        |	|dd…df         z
  d
¦  «        t          j        |
|dd…df         z
  d
¦  «        z  }t          j        ||dd…df         z
  d
¦  «        t          j        ||dd…df         z
  d
¦  «        z  }t          j        t          |¦  «        t          |¦  «        ft          j        ¬¦  «        }t          j
        |¦  «        s |dd…df         |ddd…f         z   |z
  |z   }nJt          j        |ddd…f         |dd…df         |z   |dd…df         |ddd…f         z   |z
  |z   ¦  «        }t          j        |||¬¦  «         |S )aJ  
    Calculate the intersection over union (IoU) between detection bounding boxes (dt)
    and ground-truth bounding boxes (gt).
    Reference: https://github.com/rafaelpadilla/review_object_detection_metrics

    Args:
        boxes_true: Sequence of ground-truth bounding boxes in the
            format [x, y, width, height].
        boxes_detection: Sequence of detection bounding boxes in the
            format [x, y, width, height].
        is_crowd: Sequence indicating if each ground-truth bounding box
            is a crowd region or not.

    Note:
        This function expects bounding boxes in ``[x, y, width, height]`` format
        (COCO convention). All other batch IoU functions in this module use
        ``[x_min, y_min, x_max, y_max]``.

        NaN coordinates propagate silently: if any box value is ``NaN``, the
        corresponding IoU values will be ``NaN``.

    Returns:
        Array of IoU values of shape ``(len(boxes_detection), len(boxes_true))``,
        where row ``i`` contains the IoU of detection ``i`` against all ground-truth
        boxes, and column ``j`` contains the IoU of all detections against ground-truth
        box ``j``.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> boxes_true = [
        ...     [10, 20, 30, 40],  # x, y, w, h
        ...     [15, 25, 35, 45]
        ... ]
        >>> boxes_detection = [
        ...     [12, 22, 28, 38],
        ...     [16, 26, 36, 46]
        ... ]
        >>> is_crowd = [False, False]
        >>> ious = sv.box_iou_batch_with_jaccard(
        ...     boxes_true=boxes_true,
        ...     boxes_detection=boxes_detection,
        ...     is_crowd=is_crowd
        ... )
        >>> ious  # doctest: +ELLIPSIS
        array([[0.886..., 0.496...],
               [0.4  ..., 0.862...]])

        ```
    z`is_crowd` length (z") must match `boxes_true` length (z).r   rx   rH   Né   é   rW   rz   )Úlenr+   rN   r…   r€   ÚspacingrO   Úboolr‡   rˆ   Úanyr}   rŒ   )rs   ru   r‘   ÚepsÚgtÚdtÚcrowdÚgt_x2Úgt_y2Údt_x2Údt_y2Úinter_x1Úinter_y1Úinter_x2Úinter_y2rn   rp   Úarea_gtÚiourq   s                       r   Úbox_iou_batch_with_jaccardr©   +  s  € õp ˆ8�}„}�˜J™œÒ'Ð'Ýð8¥# h¡-¤-ð 8ð 8Ý$'¨
¡O¤Oð8ð 8ð 8ñ
ô 
ð 	
õ ˆ?ÑÔ˜qÒ Ð ¥C¨
¡O¤O°qÒ$8Ð$8ÝŒx�˜_Ñ-Ô-­s°:©¬Ð?ÅrÄzÐRÑRÔRÐRõ Œ*�Q‰-Œ-€CÝ	Œ�J¥b¤jÐ	1Ñ	1Ô	1€BÝ	Œ�O­2¬:Ð	6Ñ	6Ô	6€BÝŒJ�x¥tÐ,Ñ,Ô,€Eð
 �a�a�a˜�d”8˜b    A œhÑ&¨¨1¨1¨1¨a¨4¬°2°a°a°a¸°d´8Ñ(;ˆ5€EØ�a�a�a˜�d”8˜b    A œhÑ&¨¨1¨1¨1¨a¨4¬°2°a°a°a¸°d´8Ñ(;ˆ5€Eõ Œz˜"˜Q˜Q˜Q ˜Tœ( 1 1 1 d 7Ô+¨R°°°°1°¬X°d¸A¸A¸A°gÔ->Ñ?Ô?€HÝŒz˜"˜Q˜Q˜Q ˜Tœ( 1 1 1 d 7Ô+¨R°°°°1°¬X°d¸A¸A¸A°gÔ->Ñ?Ô?€HÝŒz˜%    4 œ.¨%°°a°a°a°¬.Ñ9Ô9€HÝŒz˜%    4 œ.¨%°°a°a°a°¬.Ñ9Ô9€HÝ”˜H xÑ/°Ñ5Ô5½¼
Ø�8Ñ˜Sñ9ô 9ñ €Jõ Œz˜% " Q Q Q¨ T¤(Ñ*¨CÑ0Ô0µ2´:¸eÀbÈÈÈÈAÈÄhÑ>NÐPSÑ3TÔ3TÑT€HÝŒj˜  A A A q D¤Ñ)¨3Ñ/Ô/µ"´*¸UÀRÈÈÈÈ1ÈÄXÑ=MÈsÑ2SÔ2SÑS€Gõ $&¤8­S°©W¬Wµc¸"±g´gÐ,>ÅbÄjÐ#QÑ#QÔ#Q€CÝŒ6�%‰=Œ=ð 
Ø˜Q˜Q˜Q ˜WÔ%¨°°a°a°a°Ô(8Ñ8¸:ÑEÈÑKˆ	ˆ	å”HØ�$˜˜˜�'ŒNØ�Q�Q�Q˜�WÔ Ñ#Ø�Q�Q�Q˜�WÔ ¨¨a¨a¨a¨Ô 0Ñ0°:Ñ=ÀÑCñ
ô 
ˆ	õ
 „Iˆj˜)¨Ð-Ñ-Ô-Ð-Ø€Jr   Úpolygonsc           	     óê  — | dd…dd…dd…f         }t          j        | j        t           j        ¦  «        rTt          j        |                      t          ¦  «        |                     t          ¦  «        z
  t           j        ¬¦  «        }nE|                      t           j        d¬¦  «        }||                     t           j        d¬¦  «        z
  }|dd…dd…df         }|dd…dd…df         }|t          j        |dd¬¦  «        z  t          j        |dd¬¦  «        |z  z
  }t          t          j        t           j                 d	t          j        |                     d¬¦  «        ¦  «        z  ¦  «        S )
aí  Compute the area of each oriented-box polygon using the shoelace formula.

    Each polygon is translated to its own first corner before the shoelace
    products, keeping representable integer coordinates with large origins (e.g.
    geospatial frames) local before conversion to float64. Float inputs that
    were already quantized retain their input precision.

    Args:
        polygons: ``(N, 4, 2)`` array of polygon corners.

    Returns:
        ``(N,)`` array of polygon areas.
    Nr   rH   rx   F©Úcopyéÿÿÿÿ©Úaxisç      à?)rN   Ú
issubdtypery   ÚintegerrO   r   Úobjectr€   Úrollr   r‚   rƒ   ÚabsÚsum)rª   ÚoriginÚ
translatedÚpolygons_floatÚxÚyÚcrosss          r   Ú_polygon_areasr¾   ’  sF  € ð �a�a�a˜˜1˜˜a˜a˜a�iÔ €FÝ	„}�X”^¥R¤ZÑ0Ô0ð LÝ”ZØ�OŠO�FÑ#Ô# f§m¢mµFÑ&;Ô&;Ñ;Å2Ä:ð
ñ 
ô 
ˆ
ˆ
ð "Ÿš­¬¸%˜Ñ@Ô@ˆØ# f§m¢mµB´JÀU mÑ&KÔ&KÑKˆ
Ø�1�1�1�a�a�a˜�7Ô€AØ�1�1�1�a�a�a˜�7Ô€AØ•”˜˜2 AÐ&Ñ&Ô&Ñ&­¬°°B¸QÐ)?Ñ)?Ô)?À!Ñ)CÑC€EÝ•”�BœJÔ'¨­r¬v°e·i²iÀQ°iÑ6GÔ6GÑ/HÔ/HÑ)HÑIÔIÐIr   c                ó  — | dd…dd…df         }| dd…dd…df         }t          j        |                     d¬¦  «        |                     d¬¦  «        |                     d¬¦  «        |                     d¬¦  «        gd¬¦  «        S )zàCompute the axis-aligned bounding envelope of each oriented box.

    Args:
        polygons: ``(N, 4, 2)`` array of polygon corners.

    Returns:
        ``(N, 4)`` array of ``(x_min, y_min, x_max, y_max)`` envelopes.
    Nr   rH   r¯   )rN   Ústackr]   r\   )rª   ÚxsÚyss      r   Ú_aabb_envelopesrÃ   ®  s‹   € ð 
�!�!�!�Q�Q�Q˜�'Ô	€BØ	�!�!�!�Q�Q�Q˜�'Ô	€BÝŒ8Ø	�Š�Qˆ‰Œ˜Ÿš Q˜™œ¨¯ª°Q¨©¬¸¿ºÀQ¸¹¼ÐHÈqðñ ô ð r   Úenvelopes_trueÚenvelopes_detectionú1tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]c                ó  — | dd…ddd…f         }|ddd…dd…f         }t          j        |d         |d         ¦  «        t          j        |d         |d         ¦  «        k    t          j        |d         |d         ¦  «        t          j        |d         |d         ¦  «        k    z  }t          t          t
          j        t           j                 t
          j        t           j                 f         t          j        |¦  «        ¦  «        S )a*  Return index pairs ``(i, j)`` whose axis-aligned envelopes overlap.

    Uses a fused boolean evaluation to halve peak transient memory compared to
    named-intermediate form (4 separate NxM float64 arrays vs 1 boolean array).

    Note:
        This gate is a correctness guarantee, not an approximation: if two
        axis-aligned bounding boxes do not overlap, the convex polygons they
        contain cannot overlap either.

    Args:
        envelopes_true: ``(N, 4)`` array of ``(x_min, y_min, x_max, y_max)``
            envelopes for the ground-truth boxes.
        envelopes_detection: ``(M, 4)`` array of ``(x_min, y_min, x_max, y_max)``
            envelopes for the detection boxes.

    Returns:
        A pair of 1-D index arrays ``(rows, cols)`` identifying the overlapping
        pairs.
    N).r•   ).r   ).r–   ).rH   )	rN   rˆ   r‡   r   Útupler‚   rƒ   ÚintpÚnonzero)rÄ   rÅ   ÚetÚedÚoverlaps        r   Ú_overlapping_envelope_pairsrÎ   ¾  sÔ   € ð0 
˜˜˜˜4   ˜
Ô	#€BØ	˜T 1 1 1 a a a˜ZÔ	(€Bå
Œ
�2�f”:˜r &œzÑ*Ô*­R¬Z¸¸6¼
ÀBÀvÄJÑ-OÔ-OÒOÝ	Œ�B�v”J  6¤
Ñ	+Ô	+­b¬j¸¸F¼ÀRÈÄZÑ.PÔ.PÒ	PñR€Gõ ••c”k¥"¤'Ô*­C¬K½¼Ô,@Ð@ÔAÅ2Ä:ÈgÑCVÔCVÑWÔWÐWr   únpt.NDArray[np.floating]c                ó¶
  — d| fd|ffD ]™\  }}|j         dk    r.|j        dd…         dk    rt          d|› d|j        › d	�¦  «        ‚|j         d
k    r,|j        d         dk    rt          d|› d|j        › d�¦  «        ‚|j         dvrt          d|› d|j        › d�¦  «        ‚Œš|t          j        k    rd}n&|t          j        k    rd}nt          d|› d�¦  «        ‚| |u }|                      ddd
¦  «        } |                     ddd
¦  «        }t          | ¦  «        t          |¦  «        }}|dk    s|dk    r"t          j	        ||ft          j
        ¬¦  «        S t          | ¦  «        }	t          |¦  «        }
t          | ¦  «        }|r|nt          |¦  «        }t          ||¦  «        \  }}|r||k    }||         ||         }}t          j	        ||ft          j
        ¬¦  «        }|dd…dd
…f         }|dd…dd
…f         }t          j        | j        t          j        ¦  «        rat          j        |                      t&          ¦  «        |dd…ddd…f                              t&          ¦  «        z
  t          j        ¬¦  «        }n/| |dd…ddd…f         z
                       t          j        ¦  «        }t          j        |j        t          j        ¦  «        rat          j        |                     t&          ¦  «        |dd…ddd…f                              t&          ¦  «        z
  t          j        ¬¦  «        }n/||dd…ddd…f         z
                       t          j        ¦  «        }| j        t          j        k    r|nd}|j        t          j        k    r|nd}t          j        dt          j        ¬¦  «        }t          j        dt          j        ¬¦  «        }t-          ||¦  «        D �].\  }}|�|�||         }||         }n||         }||         }t          j        ||¦  «        }||z
                       t          j        d¬¦  «        }||z
                       t          j        d¬¦  «        }t          j        ||         ||¬¦  «         t          j        ||         ||¬¦  «         t3          j        ||¦  «        \  } }!| dk    rŒá|r|	|         |
|         z   | z
  nt7          |	|         |
|         ¦  «        }"|"dk    r| |"z  }#|#|||f<   |r|#|||f<   �Œ0t9          t:          j        t          j                 t          j         |dd¦  «        ¦  «        S )uŸ  
    Compute pairwise overlap scores between two sets of oriented bounding boxes
    using the configured `overlap_metric`.

    Overlap areas are computed exactly via convex-polygon intersection, gated by
    a cheap axis-aligned envelope pre-filter â€” no rasterization is involved, so
    the result is exact (free of pixel-quantization error) and independent of the
    coordinate magnitudes.

    `boxes_true` and `boxes_detection` are expected to be in
    `((x1, y1), (x2, y2), (x3, y3), (x4, y4))` format.

    Note:
        Inputs must be **convex** quads with finite coordinates. Self-intersecting
        or non-convex polygons produce undefined results via
        ``cv2.intersectConvexConvex``. NaN or Inf coordinates propagate silently
        as ``0.0`` â€” validate inputs before calling if needed.

        When ``boxes_true is boxes_detection`` (the same Python object, not just
        equal values), the function computes only the upper triangle of the
        matrix and mirrors it. This optimization is used automatically by the
        NMS/NMM callers that pass the same array twice. A defensive ``.copy()``
        at the call site would disable the optimization silently â€” see the
        NMS caller comment for context.

    Args:
        boxes_true: A `np.ndarray` representing ground-truth boxes.
            `shape = (N, 4, 2)` where `N` is number of true objects.
            Last axis convention: `[..., 0]` = x-coordinates,
            `[..., 1]` = y-coordinates.
        boxes_detection: A `np.ndarray` representing detection boxes.
            `shape = (M, 4, 2)` where `M` is number of detected objects.
            Last axis convention: `[..., 0]` = x-coordinates,
            `[..., 1]` = y-coordinates.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of oriented boxes (e.g., IoU, IoS).

    Returns:
        Overlap matrix of shape `(N, M)`, where entry `[i, j]` is the overlap
        score between `boxes_true[i]` and `boxes_detection[j]`, in the range
        `[0, 1]` under the configured :attr:`overlap_metric`.

    Raises:
        ValueError: If ``boxes_true`` or ``boxes_detection`` is 3-D with inner
            dimensions other than ``(4, 2)``.
        ValueError: If ``boxes_true`` or ``boxes_detection`` is 2-D with a
            column count other than 8.
        ValueError: If ``boxes_true`` or ``boxes_detection`` is not 2-D or 3-D.
        ValueError: If ``overlap_metric`` is not
            :attr:`~supervision.config.OverlapMetric.IOU` or
            :attr:`~supervision.config.OverlapMetric.IOS`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> a = np.array([[[0, 0], [2, 0], [2, 2], [0, 2]]], dtype=np.float32)
        >>> b = np.array([[[1, 0], [3, 0], [3, 2], [1, 2]]], dtype=np.float32)
        >>> sv.oriented_box_iou_batch(a, b)  # doctest: +ELLIPSIS
        array([[0.333...]])

        ```
    rs   ru   r–   rH   N©é   r•   ú`ú` has shape õV   ; expected (N, 4, 2) â€” each box must have exactly 4 corners with (x, y) coordinates.r•   é   úF; expected (N, 8) for flat YOLO format or (N, 4, 2) for corner format.©r•   r–   ú1` must be 2-D (N, 8) or 3-D (N, 4, 2), got shape ú.TFrX   rY   r®   rÒ   r   rx   r¬   rz   rW   g      ð?)!Úndimr�   r+   r<   r=   r>   Úreshaper—   rN   Úzerosr€   r¾   rÃ   rÎ   r²   ry   r³   rO   r   r´   r„   r…   Úziprˆ   ÚaddÚcv2ÚintersectConvexConvexr]   r   r‚   rƒ   ÚfloatingrŠ   )$rs   ru   rU   ÚnameÚarrÚnormalize_by_unionÚis_self_comparisonÚnÚmÚ
areas_trueÚareas_detectionrÄ   rÅ   ÚrowsÚcolsrC   ÚiousÚlocal_origins_trueÚlocal_origins_detectionÚlocal_polygons_trueÚlocal_polygons_detectionÚorigins_true_float32Úorigins_detection_float32Úpolygon_i_bufferÚpolygon_j_bufferÚiÚjÚorigin_iÚorigin_jÚpair_originÚoffset_iÚoffset_jÚintersectionÚ_ÚdenominatorÚscores$                                       r   Úoriented_box_iou_batchr  Þ  s  € ðJ $ ZÐ0Ð3DÀoÐ2VÐWð ð ‰	ˆˆcØŒ8�qŠ=ˆ=˜SœY q r rœ]¨fÒ4Ð4ÝðU�Dð Uð U c¤ið Uð Uð Uñô ð ð ŒX˜Š]ˆ]˜sœy¨œ|¨qÒ0Ð0Ýð?�Dð ?ð ? c¤ið ?ð ?ð ?ñô ð ð ŒX˜VÐ#Ð#ÝØW�DÐWÐWÈ3Ì9ÐWÐWÐWñô ð ð $ð
 �Ô*Ò*Ð*Ø!ÐÐØ	�=Ô,Ò	,Ð	,Ø"ÐÐåð1˜nð 1ð 1ð 1ñ
ô 
ð 	
ð $ Ð6ÐØ×#Ò# B¨¨1Ñ-Ô-€JØ%×-Ò-¨b°!°QÑ7Ô7€Oåˆz‰?Œ?�C Ñ0Ô0€q€AØˆA‚v€v��a’�ÝŒx˜˜A˜¥b¤jÐ1Ñ1Ô1Ð1å 
Ñ+Ô+€JÝ$ _Ñ5Ô5€Oå$ ZÑ0Ô0€Nà,ÐRˆˆµ/À/Ñ2RÔ2Rð õ -¨^Ð=PÑQÔQ�J€Dˆ$Øð .Ø˜’ˆØ˜%”[ $ u¤+ˆdˆå$&¤H¨a°¨V½2¼:Ð$FÑ$FÔ$F€DØ'¨¨¨¨2¨A¨2¨Ô.ÐØ1°!°!°!°R°a°R°%Ô8ÐÝ	„}�ZÔ%¥r¤zÑ2Ô2ð 
Ý œjØ×Ò�fÑ%Ô%Ð(:¸1¸1¸1¸dÀAÀAÀA¸:Ô(F×(MÒ(MÍfÑ(UÔ(UÑUÝ”*ð
ñ 
ô 
ÐÐð
  *Ð,>¸q¸q¸qÀ$ÈÈÈ¸zÔ,JÑJ×RÒRÝŒJñ
ô 
Ðõ 
„}�_Ô*­B¬JÑ7Ô7ð 	Ý#%¤:Ø×"Ò"¥6Ñ*Ô*Ø% a a a¨¨q¨q¨q jÔ1×8Ò8½Ñ@Ô@ñAå”*ð$
ñ $
ô $
Ð Ð ð Ð5°a°a°a¸¸q¸q¸q°jÔAÑAß
Š&•”Ñ
Ô
ð 	!ð )Ô.µ"´*Ò<Ð<ÐÐÀ$ð ð $3Ô#8½B¼JÒ#FÐ#FÐÐÈDð õ ”x ­b¬jÐ9Ñ9Ô9ÐÝ”x ­b¬jÐ9Ñ9Ô9ÐÝ�D˜$‘”ð #ñ #‰ˆˆ1ð  Ð+Ð0IÐ0UØ+¨AÔ.ˆHØ0°Ô3ˆHˆHà)¨!Ô,ˆHØ.¨qÔ1ˆHÝ”j ¨8Ñ4Ô4ˆØ˜{Ñ*×2Ò2µ2´:ÀEÐ2ÑJÔJˆØ˜{Ñ*×2Ò2µ2´:ÀEÐ2ÑJÔJˆÝ
ŒÐ" 1Ô% xÐ5EÐFÑFÔFÐFÝ
ŒÐ'¨Ô*¨HÐ:JÐKÑKÔKÐKÝÔ3Ð4DÐFVÑWÔW‰ˆ�aØ˜1ÒÐØð "ð8ˆJ�qŒM˜O¨AÔ.Ñ.°Ñ=Ð=å�Z ”] O°AÔ$6Ñ7Ô7ð 	ð
 ˜Š?ˆ?Ø  ;Ñ.ˆEØˆD��A�‰JØ!ð #Ø"��Q˜�T‘
ùõ •”�BœKÔ(­"¬'°$¸¸SÑ*AÔ*AÑBÔBÐBr   Ú
masks_truer   Úmasks_detectionc                óú  — t          | ¦  «        }t          |¦  «        }t          j        ||ft          ¬¦  «        }|dk    s|dk    r|S | j        }|j        }| j                             t          j        ¦  «        }|dd…df         }	|dd…df         }
|dd…df         }|dd…df         }|j                             t          j        ¦  «        }|dd…df         }|dd…df         }|dd…df         }|dd…df         }t          j        |	dd…df         |ddd…f         ¦  «        }t          j        |
dd…df         |ddd…f         ¦  «        }t          j	        |dd…df         |ddd…f         ¦  «        }t          j	        |dd…df         |ddd…f         ¦  «        }||k    ||k    z  }i }i }t          j
        |¦  «        D �]0}t          |d         ¦  «        t          |d         ¦  «        }}||vr|                      |¦  «        ||<   ||vr|                     |¦  «        ||<   t          |||f         ¦  «        }t          |||f         ¦  «        }t          |||f         ¦  «        }t          |||f         ¦  «        }t          |	|         ¦  «        t          |
|         ¦  «        }!} ||         ||!z
  ||!z
  dz   …|| z
  || z
  dz   …f         }"t          ||         ¦  «        t          ||         ¦  «        }$}#||         ||$z
  ||$z
  dz   …||#z
  ||#z
  dz   …f         }%t          t          j        |"|%¦  «                             ¦   «         ¦  «        }&t          ||         ¦  «        }'t          ||         ¦  «        }(|t          j        k    r|'|(z   |&z
  })|)dk    r|&|)z  nd|||f<   �Œë|t          j        k    r$t%          |'|(¦  «        }*|*dk    r|&|*z  nd|||f<   �Œt'          d|› d	�¦  «        ‚|S )
u.  Compute pairwise overlap between two :class:`CompactMask` collections.

    Avoids materialising full ``(N, H, W)`` arrays by:

    1. Vectorised bounding-box pre-filter â€” pairs whose boxes do not overlap
       get IoU = 0 without any mask decoding.
    2. Sub-crop decoding â€” for overlapping pairs, only the intersection region
       of each crop is decoded and compared.
    3. Crop caching â€” each individual crop is decoded at most once even when it
       participates in many pairs.

    The result is numerically identical to running the dense
    :func:`mask_iou_batch` on ``np.asarray(masks_true)`` /
    ``np.asarray(masks_detection)``.

    Args:
        masks_true: :class:`~supervision.detection.compact_mask.CompactMask`
            holding the ground-truth masks.
        masks_detection: :class:`~supervision.detection.compact_mask.CompactMask`
            holding the detection masks.
        overlap_metric: :class:`OverlapMetric` â€” ``IOU`` or ``IOS``.

    Returns:
        Float array of shape ``(N1, N2)`` with pairwise overlap values.
    rx   r   NrH   r•   r–   rW   rX   rY   )r—   rN   rÝ   rE   ÚareaÚ	bbox_xyxyr   Úint32r‡   rˆ   ÚargwhereÚintÚcropÚlogical_andr·   r<   r=   r>   r]   r+   )+r  r  rU   Ún1Ún2ÚresultÚareas_aÚareas_bÚbboxes_aÚx1aÚy1aÚx2aÚy2aÚbboxes_bÚx1bÚy1bÚx2bÚy2bÚix1Úiy1Úix2Úiy2Úbbox_overlapÚcrops_aÚcrops_bÚidx_pairÚidx_aÚidx_bÚlx1Úly1Úlx2Úly2Úox_aÚoy_aÚsub_aÚox_bÚoy_bÚsub_bÚinterÚarea_a_iÚarea_b_jÚunionÚsmalls+                                              r   Úcompact_mask_iou_batchr4  š  sC  € õ< �*‰oŒo€BÝ�/Ñ"Ô"€BÝ')¤x°°R°ÅÐ'FÑ'FÔ'F€Fà	ˆQ‚w€w�"˜’'�'Øˆà%/¤_€GØ%4Ô%9€Gð '1Ô&:×&AÒ&AÅ"Ä(Ñ&KÔ&K€HØ!)¨!¨!¨!¨Q¨$¤€CØ!)¨!¨!¨!¨Q¨$¤€CØ!)¨!¨!¨!¨Q¨$¤€CØ!)¨!¨!¨!¨Q¨$¤€Cà&5Ô&?×&FÒ&FÅrÄxÑ&PÔ&P€HØ!)¨!¨!¨!¨Q¨$¤€CØ!)¨!¨!¨!¨Q¨$¤€CØ!)¨!¨!¨!¨Q¨$¤€CØ!)¨!¨!¨!¨Q¨$¤€Cõ "$¤¨C°°°°4°¬L¸#¸dÀAÀAÀA¸g¼,Ñ!GÔ!G€CÝ!#¤¨C°°°°4°¬L¸#¸dÀAÀAÀA¸g¼,Ñ!GÔ!G€CÝ!#¤¨C°°°°4°¬L¸#¸dÀAÀAÀA¸g¼,Ñ!GÔ!G€CÝ!#¤¨C°°°°4°¬L¸#¸dÀAÀAÀA¸g¼,Ñ!GÔ!G€CØ+.°#ª:¸#Àº*Ñ*E€Lð 13€GØ02€Gå”K Ñ-Ô-ð !ñ !ˆÝ˜8 Aœ;Ñ'Ô'­¨X°a¬[Ñ)9Ô)9ˆuˆà˜ÐÐØ'Ÿ_š_¨UÑ3Ô3ˆG�E‰NØ˜ÐÐØ,×1Ò1°%Ñ8Ô8ˆG�E‰Nå�#�e˜U�lÔ#Ñ$Ô$ˆÝ�#�e˜U�lÔ#Ñ$Ô$ˆÝ�#�e˜U�lÔ#Ñ$Ô$ˆÝ�#�e˜U�lÔ#Ñ$Ô$ˆå˜˜Uœ‘_”_¥c¨#¨e¬*¡o¤oˆdˆØ˜”˜s T™z¨C°$©J¸©NÐ:¸CÀ$¹JÈÈtÉÐVWÉÐ<WÐWÔXˆå˜˜Uœ‘_”_¥c¨#¨e¬*¡o¤oˆdˆØ˜”˜s T™z¨C°$©J¸©NÐ:¸CÀ$¹JÈÈtÉÐVWÉÐ<WÐWÔXˆå•B”N 5¨%Ñ0Ô0×4Ò4Ñ6Ô6Ñ7Ô7ˆÝ�w˜u”~Ñ&Ô&ˆÝ�w˜u”~Ñ&Ô&ˆà�]Ô.Ò.Ð.Ø˜xÑ'¨%Ñ/ˆEØ49¸A²I°I 5¨5¡= =À3ˆF�5˜%�<Ñ Ñ Ø�}Ô0Ò0Ð0Ý˜ (Ñ+Ô+ˆEØ49¸A²I°I 5¨5¡= =À3ˆF�5˜%�<Ñ Ñ åð5 .ð 5ð 5ð 5ñô ð ð
 €Mr   únpt.NDArray[Any]c                óø  — t          t          j        | j        dd…         ¦  «        ¦  «        }|dk    rt          j        nt          j        }t          t          j        t          j	                 |  
                    | j        d         |¦  «                             |d¬¦  «        ¦  «        }t          t          j        t          j	                 | 
                    |j        d         |¦  «                             |d¬¦  «        ¦  «        }t          j        ddd¬¦  «        5  ||j        z  }ddd¦  «         n# 1 swxY w Y   |                     d¬	¦  «        }|                     d¬	¦  «        }	|t          j        k    rH|dd…df         |	z   |z
  }
t          j        ||
t          j        |t&          ¬
¦  «        |
dk    ¬¦  «        }nx|t          j        k    rUt          j        |dd…df         |	¦  «        }t          j        ||t          j        |t&          ¬
¦  «        |dk    ¬¦  «        }nt-          d|› d�¦  «        ‚t          j        |¦  «        }t          t          j        t          j	                 |¦  «        S )aï  
    Internal function.
    Compute Intersection over Union (IoU) of two sets of masks -
        `masks_true` and `masks_detection`.

    Args:
        masks_true: 3D `np.ndarray` representing ground-truth masks.
        masks_detection: 3D `np.ndarray` representing detection masks.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of masks (e.g., IoU, IoS).

    Returns:
        Pairwise IoU of masks from `masks_true` and `masks_detection`.
    rH   Né   r   Fr¬   Úignore)rŒ   ÚoverÚinvalidr¯   rx   r|   rX   rY   )r	  rN   Úprodr�   r„   r€   r   r‚   rƒ   râ   rÜ   r   Úerrstater~   r·   r<   r=   rŒ   r‹   rE   r>   rˆ   r+   Ú
nan_to_num)r  r  rU   ÚpixelsÚcount_dtypeÚ	true_flatÚdetection_flatÚintersection_areaÚmasks_true_areaÚmasks_detection_areaÚ
union_arearí   Ú
small_areas                r   Ú_mask_iou_batch_splitrG    s±  € õ. •”˜Ô)¨!¨"¨"Ô-Ñ.Ô.Ñ/Ô/€FØ &¨%¢ •"”*�*µR´Z€KÝÝŒ•B”KÔ Ø×Ò˜:Ô+¨AÔ.°Ñ7Ô7×>Ò>¸{ÐQVÐ>ÑWÔWñô €Iõ ÝŒ•B”KÔ Ø×Ò Ô 5°aÔ 8¸&ÑAÔA×HÒHØ˜eð 	Iñ 	
ô 	
ñô €Nõ 
Œ˜H¨8¸XÐ	FÑ	FÔ	Fð Xð XØ;DÀ~ÔGWÑ;WÐðXð Xð Xñ Xô Xð Xð Xð Xð Xð Xð Xøøøð Xð Xð Xð Xð  —m’m¨�mÑ+Ô+€OØ)×-Ò-°1Ð-Ñ5Ô5Ðà�Ô*Ò*Ð*Ø$ Q Q Q¨ WÔ-Ð0DÑDÐGXÑXˆ
ÝŒyØØÝ”Ð/µuÐ=Ñ=Ô=Ø ’/ð	
ñ 
ô 
ˆˆð 
�=Ô,Ò	,Ð	,å”Z °°°°4°Ô 8Ð:NÑOÔOˆ
ÝŒyØØÝ”Ð/µuÐ=Ñ=Ô=Ø ’/ð	
ñ 
ô 
ˆˆõ ð1˜nð 1ð 1ð 1ñ
ô 
ð 	
õ
 Œ=˜ÑÔ€DÝ•”�BœKÔ(¨$Ñ/Ô/Ð/s   Ä D7Ä7D;Ä>D;i   únpt.NDArray[Any] | CompactMaskÚmemory_limitr	  c           	     óF  — t          | t          ¦  «        r&t          |t          ¦  «        rt          | ||¦  «        S t          | t          ¦  «        rt          j        | ¦  «        } t          |t          ¦  «        rt          j        |¦  «        }| j        dk    s|j        dk    r t          d| j        › d|j        › d�¦  «        ‚| j        dd…         |j        dd…         k    r0t          d| j        dd…         › d|j        dd…         › d�¦  «        ‚| j        d	         d	k    s|j        d	         d	k    rt          | ||¦  «        S | j        d         | j        d
         z  }|dk    rdnd}|dz  dz  }|j        d	         |z  |z  }||z  d|j        d	         z  dz  z   }||cxk    rd	k    r,n n)t          j
        d|dz  dz  › d|› d�t          d
¬¦  «         || j        d	         |z  z   |k    rt          | ||¦  «        S g }	t          ||z
  |z  d¦  «        }
t          d	| j        d	         |
¦  «        D ]1}|	                     t          | |||
z   …         ||¦  «        ¦  «         Œ2t          t           j        t          j                 t          j        |	¦  «        ¦  «        S )aX  
    Compute Intersection over Union (IoU) of two sets of masks -
        `masks_true` and `masks_detection`.

    Accepts both dense ``(N, H, W)`` boolean arrays and
    :class:`~supervision.detection.compact_mask.CompactMask` objects.
    When both inputs are :class:`~supervision.detection.compact_mask.CompactMask`,
    the computation uses :func:`compact_mask_iou_batch` to avoid materialising
    full ``(N, H, W)`` arrays.

    Args:
        masks_true: 3D `np.ndarray` representing ground-truth masks.
        masks_detection: 3D `np.ndarray` representing detection masks.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of masks (e.g., IoU, IoS).
        memory_limit: Memory limit in MB, default is 1024 * 5 MB (5GB).
            Controls chunking of ``masks_true`` so that flattened detection
            masks plus each chunk's buffers stay within this limit. A
            ``UserWarning`` is raised when ``masks_detection`` alone
            exceeds the limit, as chunking cannot reduce peak memory
            below that floor. Ignored when both inputs are
            :class:`~supervision.detection.compact_mask.CompactMask`.

    Returns:
        Pairwise IoU of masks from `masks_true` and `masks_detection`.

    Raises:
        ValueError: If ``masks_true`` or ``masks_detection`` are not 3D
            ``(N, H, W)`` arrays, or if they do not share the same
            spatial dimensions ``(H, W)``.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> masks_true = np.zeros((1, 4, 4), dtype=bool)
        >>> masks_true[:, :2, :2] = True
        >>> masks_detection = np.zeros((1, 4, 4), dtype=bool)
        >>> masks_detection[:, :3, :3] = True
        >>> sv.mask_iou_batch(masks_true, masks_detection)
        array([[0.44444445]])

        ```
    r–   z>masks_true and masks_detection must be 3D (N, H, W); got ndim=z
 and ndim=rÚ   rH   Nz?masks_true and masks_detection must share the same (H, W); got ú and r   r•   r7  rÒ   rÖ   i   zdetection masks (z MB) exceed memory_limit (z: MB); chunking cannot reduce peak memory below this floor.)Ú
stacklevel)r(   r
   r4  rN   rO   rÛ   r+   r�   rG  ÚwarningsÚwarnÚUserWarningr\   ÚrangeÚappendr   r‚   rƒ   râ   Úvstack)r  r  rU   rI  r>  ÚitemsizeÚlimit_bytesÚdetection_bytesÚper_true_rowrí   ÚstepÚchunk_starts               r   Úmask_iou_batchrY  E  sF  € õf �*�kÑ*Ô*ð S­z¸/Í;Ñ/WÔ/Wð SÝ% j°/À>ÑRÔRÐRõ �*�kÑ*Ô*ð ,Ý”Z 
Ñ+Ô+ˆ
Ý�/¥;Ñ/Ô/ð 6Ýœ* _Ñ5Ô5ˆà„˜!ÒÐ˜Ô3°qÒ8Ð8ÝðGØ”OðGð GØ/>Ô/CðGð Gð Gñ
ô 
ð 	
ð Ô˜˜˜Ô˜Ô4°Q°R°RÔ8Ò8Ð8ÝðGØÔ   Ô#ðGð GØ*9Ô*?ÀÀÀÔ*CðGð Gð Gñ
ô 
ð 	
ð
 Ô˜Ô˜aÒÐ ?Ô#8¸Ô#;¸qÒ#@Ð#@Ý$ Z°À.ÑQÔQÐQð Ô˜aÔ  :Ô#3°AÔ#6Ñ6€FØ˜e’O�Oˆqˆq¨€HØ Ñ%¨Ñ,€KØ%Ô+¨AÔ.°Ñ7¸(ÑB€OØ˜HÑ$ q¨?Ô+@ÀÔ+CÑ'CÀaÑ'GÑG€LØ˜Ð(Ð(Ò(Ð( qÒ(Ð(Ð(Ð(Ð(ÝŒð' °4Ñ 7¸4Ñ ?ð 'ð 'Ø)ð'ð 'ð 'õ Øð	
ñ 	
ô 	
ð 	
ð ˜Ô)¨!Ô,¨|Ñ;Ñ;¸{ÒJÐJÝ$ Z°À.ÑQÔQÐQà€DÝ�˜oÑ-°,Ñ>ÀÑBÔB€DÝ˜Q 
Ô 0°Ô 3°TÑ:Ô:ð 
ð 
ˆØ�ŠÝ!Ø˜;¨°tÑ);Ð;Ô<ØØñô ñ	
ô 	
ð 	
ð 	
õ •”�BœKÔ(­"¬)°D©/¬/Ñ:Ô:Ð:r   r±   i€  ÚpredictionsÚmasksÚmask_dimensionúnpt.NDArray[np.bool_]c                ó¼  — t          |¦  «         | j        \  }}|dk    r&t          j        | t          j        |¦  «        f         } | dd…df                              ¦   «         ddd…         }| |         } ||         }t          |||¦  «        }| dd…df         }	t          j        |t          ¬¦  «        }
t          |¦  «        D ]W}|
|         rM||         |k    |	|         |	k    z  }t          j
        ||dz   d…         d|
|dz   d…         ¦  «        |
|dz   d…<   ŒXt          t          j        t          j                 |
|                     ¦   «                  ¦  «        S )uC  
    Perform Non-Maximum Suppression (NMS) on segmentation predictions.

    IoU is computed exactly on the full-resolution masks for both dense and
    :class:`~supervision.detection.compact_mask.CompactMask` inputs.  The
    ``mask_dimension`` parameter is kept for backward compatibility but is no
    longer used â€” dense masks are **not** resized before IoU computation.

    Args:
        predictions: A 2D array of object detection predictions in
            the format of `(x_min, y_min, x_max, y_max, score)`
            or `(x_min, y_min, x_max, y_max, score, class)`. Shape: `(N, 5)` or
            `(N, 6)`, where N is the number of predictions.
        masks: A 3D array of binary masks corresponding to the predictions.
            Shape: `(N, H, W)`, where N is the number of predictions, and H, W are the
            dimensions of each mask.
        iou_threshold: The intersection-over-union threshold
            to use for non-maximum suppression.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of masks (e.g., IoU, IoS).
        mask_dimension: Deprecated, no longer used. Kept for backward
            compatibility.

    Returns:
        A boolean array indicating which predictions to keep after
            non-maximum suppression.

    Raises:
        ValueError: If `iou_threshold` is not within the closed range
            from `0` to `1`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> predictions = np.array([
        ...     [0, 0, 4, 4, 0.9, 0],
        ...     [0, 0, 4, 4, 0.8, 0],
        ... ])
        >>> masks = np.zeros((2, 4, 4), dtype=bool)
        >>> masks[:, :2, :2] = True
        >>> sv.mask_non_max_suppression(predictions, masks, iou_threshold=0.5)
        array([ True, False])

        ```
    é   NrÒ   r®   rx   rH   F)rK   r�   rN   Úc_rÝ   ÚargsortrY  Úonesr™   rP  r}   r   r‚   rƒ   Úbool_)rZ  r[  rD   rU   r\  rë   ÚcolumnsÚ
sort_indexrí   Ú
categoriesÚkeepÚrow_idxÚ	conditions                r   Úmask_non_max_suppressionrj  ²  sd  € õj ˜MÑ*Ô*Ð*ØÔ%�M€Dˆ'à�!‚|€|Ý”e˜K­¬°$©¬Ð7Ô8ˆà˜Q˜Q˜Q ˜TÔ"×*Ò*Ñ,Ô,¨T¨T¨r¨TÔ2€JØ˜jÔ)€KØ�*Ô€Eå˜% ¨Ñ7Ô7€DØ˜Q˜Q˜Q ˜TÔ"€JåŒ7�4�tÐ$Ñ$Ô$€DÝ˜‘;”;ð ð ˆØ�Œ=ð 	Ø˜gœ¨Ò6Ø˜7Ô# zÒ1ñˆIõ #%¤(Ø˜' A™+˜-˜-Ô(¨%°°gÀ±k°m°mÔ1Dñ#ô #ˆD�˜1‘��Ñøõ •”�BœHÔ% t¨J×,>Ò,>Ñ,@Ô,@Ô'AÑBÔBÐBr   Úsigmac                ó   — t          |¦  «         | j        \  }}|dk    r&t          j        | t          j        |¦  «        f         } | dd…df                              ¦   «         ddd…         }| |         } ||         }t          |||¦  «        }| dd…df         }	t          ||	| dd…df         |¦  «        }
|
|                     ¦   «                  S )uT
  
    Perform Soft Non-Maximum Suppression (Soft-NMS) on segmentation predictions.

    Unlike `mask_non_max_suppression`, which discards overlapping masks outright,
    Soft-NMS keeps every detection and instead rescales its confidence by
    `score *= exp(-iou**2 / sigma)` for each higher-scoring, same-category
    overlap â€” the caller decides whether and where to threshold the result.
    A smaller `sigma` produces a stronger decay.

    The 3rd positional parameter here is `sigma`, not `iou_threshold` as in
    `mask_non_max_suppression` â€” Soft-NMS has no threshold to suppress at, only
    a decay strength, so the two signatures intentionally diverge at that
    position.

    IoU is computed exactly on the full-resolution masks for both dense and
    :class:`~supervision.detection.compact_mask.CompactMask` inputs. The
    `mask_dimension` parameter is kept for signature parity with
    `mask_non_max_suppression` but is not used â€” dense masks are **not** resized
    before IoU computation.

    Args:
        predictions: A 2D array of object detection predictions in
            the format of `(x_min, y_min, x_max, y_max, score)`
            or `(x_min, y_min, x_max, y_max, score, class)`. Shape: `(N, 5)` or
            `(N, 6)`, where N is the number of predictions.
        masks: A 3D array of binary masks corresponding to the predictions.
            Shape: `(N, H, W)`, where N is the number of predictions, and H, W are the
            dimensions of each mask.
        sigma: Controls the strength of the confidence decay; must be greater
            than `0`. No value of `sigma` reproduces hard
            `mask_non_max_suppression` output â€” Soft-NMS never drops masks, only
            rescales confidence.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of masks (e.g., IoU, IoS).
        mask_dimension: Deprecated, unused. Kept for signature parity with
            `mask_non_max_suppression`.

    Returns:
        An array containing the updated (decayed) confidence scores, in the
            same order as the input `predictions`.

    Raises:
        ValueError: If `sigma` is not greater than `0`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> predictions = np.array([
        ...     [0, 0, 4, 4, 0.9, 0],
        ...     [0, 0, 4, 4, 0.8, 0],
        ... ])
        >>> masks = np.zeros((2, 4, 4), dtype=bool)
        >>> masks[:, :2, :2] = True
        >>> sv.mask_soft_non_max_suppression(predictions, masks, sigma=0.5)
        array([0.9       , 0.10826823])

        ```
    r_  NrÒ   r®   )Ú_validate_sigmar�   rN   r`  rÝ   ra  rY  Ú_soft_nms_decay_from_iou_matrix)rZ  r[  rk  rU   r\  rë   rd  re  rí   rf  Údecayeds              r   Úmask_soft_non_max_suppressionrp    sß   € õD �EÑÔÐØÔ%�M€Dˆ'à�!‚|€|Ý”e˜K­¬°$©¬Ð7Ô8ˆà˜Q˜Q˜Q ˜TÔ"×*Ò*Ñ,Ô,¨T¨T¨r¨TÔ2€JØ˜jÔ)€KØ�*Ô€Eå˜% ¨Ñ7Ô7€DØ˜Q˜Q˜Q ˜TÔ"€Jå-Øˆj˜+ a a a¨ dÔ+¨Uñô €Gð �:×%Ò%Ñ'Ô'Ô(Ð(r   úOtuple[npt.NDArray[np.int_], npt.NDArray[np.floating], npt.NDArray[np.floating]]c                ó   — | j         \  }}|dk    r&t          j        | t          j        |¦  «        f         } t          j        | dd…df                              ¦   «         ¦  «        }| |         } | dd…df         }|| |fS )zÏAdd an agnostic class column when missing, sort by descending score.

    Returns the score-descending sort index, the reordered predictions, and the
    category vector for the loop callers to consume.
    r_  NrÒ   )r�   rN   r`  rÝ   Úflipra  )rZ  rë   rd  re  rf  s        r   Ú_prepare_predictions_for_nmsrt  V  sƒ   € ð  Ô%�M€Dˆ'Ø�!‚|€|Ý”e˜K­¬°$©¬Ð7Ô8ˆÝ”˜ Q Q Q¨ TÔ*×2Ò2Ñ4Ô4Ñ5Ô5€JØ˜jÔ)€KØ˜Q˜Q˜Q ˜TÔ"€JØ�{ JÐ.Ð.r   rí   rf  c                ó  — t          | ¦  «        }| t          j        |¦  «        z
  } t          j        |t          ¬¦  «        }t          t          | |¦  «        ¦  «        D ]$\  }\  }}||         sŒ||k    ||k    z  }|| z  }Œ%|S )a  Greedy NMS suppression loop given a precomputed pairwise IoU matrix.

    Assumes `ious` is square with row/column order matching `categories`.
    Detections sharing a category whose IoU exceeds `iou_threshold` are dropped
    in favour of the higher-confidence entry.
    rx   )r—   rN   Úeyerb  r™   Ú	enumeraterÞ   )	rí   rf  rD   rë   rg  Úindexr¨   Úcategoryri  s	            r   Ú_nms_loop_from_iou_matrixrz  g  s•   € õ ˆt‰9Œ9€DØ•"”&˜‘,”,Ñ€DÝ"$¤'¨$µdÐ";Ñ";Ô";€DÝ"+­C°°jÑ,AÔ,AÑ"BÔ"Bð !ð !Ñˆ‰��XØ�EŒ{ð 	ØØ˜=Ò(¨Z¸8Ò-CÑDˆ	Ø�y�jÑ ˆˆØ€Kr   c                ó8   — | dk    st          d| › d�¦  «        ‚dS )zDRaise `ValueError` when a Soft-NMS `sigma` is not strictly positive.r   z)Value of `sigma` must be greater than 0, rI   NrJ   )rk  s    r   rm  rm  }  s,   € à�1Š9ˆ9ÝÐSÀUÐSÐSÐSÑTÔTÐTð ˆ9r   Úscoresc                ó   — t          | ¦  «        }|dd…df         |ddd…f         k    }t          j        t          j        ||ft          ¬¦  «        d¬¦  «        }t          j        ||z  | dz  d¦  «        }|                     d¬¦  «        }t          t          j	        t          j
                 |t          j        | |z  ¦  «        z  ¦  «        S )	uo  Vectorized Gaussian Soft-NMS confidence decay given a precomputed IoU matrix.

    Assumes `ious`, `categories`, and `scores` are all sorted by descending score
    (as produced by `_prepare_predictions_for_nms`), and that `ious` is square with
    row/column order matching `categories`. Each detection's score is decayed once
    per higher-scoring, same-category detection that precedes it â€” equivalent to
    the reference single-pass (no re-sort) Soft-NMS loop, computed as a single
    vectorized closed form: `decayed[j] = scores[j] * exp(-sum_i(ious[i, j]**2) /
    sigma)` summed over same-category `i < j`.
    Nrx   rH   )Úkr•   rW   r   r¯   )r—   rN   Útriurb  r™   r}   r·   r   r‚   rƒ   râ   Úexp)	rí   rf  r|  rk  rë   Úsame_categoryÚprecedesÚweighted_iou_sqÚdecay_exponents	            r   rn  rn  ƒ  s»   € õ  ˆt‰9Œ9€DØ˜q˜q˜q $˜wÔ'¨:°d¸A¸A¸A°gÔ+>Ò>€MÝŒw•r”w  d˜|µ4Ð8Ñ8Ô8¸AÐ>Ñ>Ô>€HÝ”h˜x¨-Ñ7¸¸q¹À#ÑFÔF€OØ$×(Ò(¨aÐ(Ñ0Ô0€NÝ•”�BœKÔ(¨&µ2´6¸>¸/ÈEÑ:QÑ3RÔ3RÑ*RÑSÔSÐSr   c                óò   — t          |¦  «         t          | ¦  «        \  }} }t          | dd…dd…f         | dd…dd…f         |¦  «        }t          |||¦  «        }||                     ¦   «                  }|S )a<  
    Perform Non-Maximum Suppression (NMS) on object detection predictions.

    Args:
        predictions: An array of object detection predictions in
            the format of `(x_min, y_min, x_max, y_max, score)`
            or `(x_min, y_min, x_max, y_max, score, class)`.
        iou_threshold: The intersection-over-union threshold
            to use for non-maximum suppression.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of boxes (e.g., IoU, IoS).

    Returns:
        A boolean array indicating which predictions to keep after
            non-maximum suppression.

    Raises:
        ValueError: If `iou_threshold` is not within the closed range
            from `0` to `1`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> predictions = np.array([
        ...     [0, 0, 4, 4, 0.9, 0],
        ...     [0, 0, 4, 4, 0.8, 0],
        ... ])
        >>> sv.box_non_max_suppression(predictions, iou_threshold=0.5)
        array([ True, False])

        ```
    NrÒ   )rK   rt  r�   rz  ra  )rZ  rD   rU   re  rf  rí   rg  r  s           r   Úbox_non_max_suppressionr†  ›  s†   € õL ˜MÑ*Ô*Ð*Ý*FÀ{Ñ*SÔ*SÑ'€J�˜ZÝ˜ Q Q Q¨¨¨ UÔ+¨[¸¸¸¸B¸Q¸B¸Ô-?ÀÑPÔP€DÝ$ T¨:°}ÑEÔE€DØ$(¨×);Ò);Ñ)=Ô)=Ô$>€FØ€Mr   c                ó  — t          |¦  «         t          | ¦  «        \  }} }t          | dd…dd…f         | dd…dd…f         |¦  «        }t          ||| dd…df         |¦  «        }||                     ¦   «                  }|S )u-  
    Perform Soft Non-Maximum Suppression (Soft-NMS) on object detection predictions.

    Unlike `box_non_max_suppression`, which discards overlapping boxes outright,
    Soft-NMS keeps every detection and instead rescales its confidence by
    `score *= exp(-iou**2 / sigma)` for each higher-scoring, same-category
    overlap â€” the caller decides whether and where to threshold the result.
    A smaller `sigma` produces a stronger decay.

    Args:
        predictions: An array of object detection predictions in
            the format of `(x_min, y_min, x_max, y_max, score)`
            or `(x_min, y_min, x_max, y_max, score, class)`.
        sigma: Controls the strength of the confidence decay; must be greater
            than `0`. No value of `sigma` reproduces hard
            `box_non_max_suppression` output â€” Soft-NMS never drops boxes, only
            rescales confidence.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of boxes (e.g., IoU, IoS).

    Returns:
        An array containing the updated (decayed) confidence scores, in the
            same order as the input `predictions`.

    Raises:
        ValueError: If `sigma` is not greater than `0`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> predictions = np.array([
        ...     [0, 0, 4, 4, 0.9, 0],
        ...     [0, 0, 4, 4, 0.8, 0],
        ... ])
        >>> sv.box_soft_non_max_suppression(predictions, sigma=0.5)
        array([0.9       , 0.10826823])

        ```
    NrÒ   )rm  rt  r�   rn  ra  )rZ  rk  rU   re  rf  rí   ro  Úresult_scoress           r   Úbox_soft_non_max_suppressionr‰  É  s�   € õZ �EÑÔÐÝ*FÀ{Ñ*SÔ*SÑ'€J�˜ZÝ˜ Q Q Q¨¨¨ UÔ+¨[¸¸¸¸B¸Q¸B¸Ô-?ÀÑPÔP€DÝ-Øˆj˜+ a a a¨ dÔ+¨Uñô €Gð /6°j×6HÒ6HÑ6JÔ6JÔ.K€MØÐr   úlist[list[int]]c                óZ  — g }| dd…df         }|                      ¦   «         }t          |¦  «        dk    �rtt          |d         ¦  «        }|dd…         }t          |¦  «        dk    r|                     |g¦  «         �n*||         d         }|g}	t          |¦  «        dk    rÝt	          ||         ||¦  «        }
|
                     ¦   «         |k    }|                     ¦   «         sn™||         }t          j         	                    t          j
        ||         |g¦  «        dd¬¦  «        }|	                     t          j        |¦  «                             ¦   «         ¦  «         ||          }t          |¦  «        dk    °Ý|                     |	¦  «         t          |¦  «        dk    �°t|S )aË  
    Apply greedy version of non-maximum merging to avoid detecting too many

    Args:
        predictions: An array of shape `(n, 5)` containing
            the bounding boxes coordinates in format `[x1, y1, x2, y2]`
            and the confidence scores.
        masks: A 3D array of binary masks corresponding to
            the predictions.
        iou_threshold: The intersection-over-union threshold
            to use for non-maximum suppression. Defaults to 0.5.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of masks (e.g., IoU, IoS).

    Returns:
        Groups of prediction indices to be merged.
            Each group may have 1 or more elements.
    NrÒ   r   r®   ©N.T©r°   Úkeepdims)ra  r—   r	  rQ  rY  Úflattenrš   rN   Ú
logical_orÚreduceÚconcatenateÚextendrs  Útolist)rZ  r[  rD   rU   Úmerge_groupsr|  ÚorderÚidxÚmerge_candidateÚcandidate_groupsrí   Úabove_thresholdÚ	above_idxs                r   Ú_group_overlapping_masksrœ     s�  € ð0 %'€Là˜˜˜˜A˜Ô€FØ�NŠNÑÔ€Eå
ˆe‰*Œ*�qŠ.‰.Ý�%˜”)‰nŒnˆà�c�r�c”
ˆÝˆu‰:Œ:˜Š?ˆ?Ø×Ò  Ñ&Ô&Ð&Ùà œ* YÔ/ˆØ˜5ÐÝ�%‰jŒj˜1ŠnˆnÝ! %¨¤,°ÀÑPÔPˆDØ59·\²\±^´^À}Ò5TˆOØ"×&Ò&Ñ(Ô(ð ØØ˜oÔ.ˆIÝ œm×2Ò2Ý”  iÔ 0°/ÐBÑCÔCØØð 3ñ ô ˆOð
 ×#Ò#¥B¤G¨IÑ$6Ô$6×$=Ò$=Ñ$?Ô$?Ñ@Ô@Ð@Ø˜?Ð*Ô+ˆEõ �%‰jŒj˜1Šnˆnð 	×ÒÐ,Ñ-Ô-Ð-õ1 ˆe‰*Œ*�qŠ.‰.ð2 Ðr   )rU   r\  Úargsc               óâ  ‡ ‡‡‡— t          ‰¦  «         t          |¦  «        dk    rt          d¦  «        ‚|rŸt          d¦  «         |d         }t	          |t
          ¦  «        r|Šnt          t          |¦  «        }t          |¦  «        dk    rH|d         }t	          |t
          ¦  «        rt          t          |¦  «        }nt          t
          |¦  «        Š~dˆˆˆˆ fd
„}t          ‰ |¦  «        S )aw  
    Perform Non-Maximum Merging (NMM) on segmentation predictions.

    Args:
        predictions: A 2D array of object detection predictions in
            the format of `(x_min, y_min, x_max, y_max, score)`
            or `(x_min, y_min, x_max, y_max, score, class)`. Shape: `(N, 5)` or
            `(N, 6)`, where N is the number of predictions.
        masks: A 3D array of binary masks corresponding to the predictions.
            Shape: `(N, H, W)`, where N is the number of predictions, and H, W are the
            dimensions of each mask.
        iou_threshold: The intersection-over-union threshold
            to use for non-maximum merging.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of masks (e.g., IoU, IoS).
        mask_dimension: Deprecated in `0.30.0`, removed in `0.33.0`. No longer
            used; the parameter is silently ignored. Passing `mask_dimension`
            positionally emits a deprecation warning.

    Returns:
        A list of groups of prediction indices. Each inner list contains
            the indices of predictions whose masks overlap above `iou_threshold`
            according to the chosen `overlap_metric`, and should be merged or
            kept together as a single detection by non-maximum merging.

    Raises:
        ValueError: If `iou_threshold` is not within the closed range
            from `0` to `1`.
        TypeError: If more than five positional arguments are passed.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> predictions = np.array([
        ...     [0, 0, 4, 4, 0.9, 0],
        ...     [0, 0, 4, 4, 0.8, 0],
        ... ])
        >>> masks = np.zeros((2, 4, 4), dtype=bool)
        >>> masks[:, :2, :2] = True
        >>> sv.mask_non_max_merge(predictions, masks, iou_threshold=0.5)
        [[0, 1]]

        ```
    r•   zpmask_non_max_merge accepts at most five positional arguments. Pass overlap_metric and mask_dimension by keyword.zªPassing `overlap_metric` or `mask_dimension` positionally to `mask_non_max_merge` is deprecated in `0.30.0` and will be removed in `0.33.0`. Pass them by keyword instead.r   rH   Úglobal_indicesúnpt.NDArray[np.int_]r   rŠ  c                ó¦   •— t          ‰t          ¦  «        rt          ‰|          ‰|          ‰‰¦  «        S t          ‰|          ‰|          ‰‰¦  «        S r   )r(   r
   Ú!_group_overlapping_masks_pairwiserœ  )rŸ  rD   r[  rU   rZ  s    €€€€r   Úgroup_withinz(mask_non_max_merge.<locals>.group_within‰  sg   ø€ Ý�e�[Ñ)Ô)ð 	Ý4Ø˜NÔ+Ø�nÔ%ØØñ	ô ð õ (Ø˜Ô'Ø�.Ô!ØØñ	
ô 
ð 	
r   ©rŸ  r   r   rŠ  )	rK   r—   r[   r   r(   r<   r   r	  Ú_non_max_merge_per_category)	rZ  r[  rD   rU   r\  r�  ÚfirstÚsecondr£  s	   ````     r   Úmask_non_max_merger¨  9  s  øøøø€ õl ˜MÑ*Ô*Ð*Ý
ˆ4�y„y�1‚}€}ÝðAñ
ô 
ð 	
ð ð =Ýð9ñ	
ô 	
ð 	
ð
 �Q”ˆÝ�e�]Ñ+Ô+ð 	.Ø"ˆNˆNå!¥# uÑ-Ô-ˆNÝˆt‰9Œ9˜Š>ˆ>Ø˜!”WˆFÝ˜%¥Ñ/Ô/ð =Ý!%¥c¨6Ñ!2Ô!2��å!%¥m°VÑ!<Ô!<�àð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
õ ' {°LÑAÔAÐAr   Ú	candidater›  r   c                ó.  — t          | t          ¦  «        ržt          t          |¦  «        }t          j                             t          j        | |                              ¦   «         |                     ¦   «         g¦  «        dd¬¦  «        }t          j        |t          |¦  «        | j
        ¬¦  «        S t          t          j        t                   |¦  «        }t          j                             t          j        | |         |g¦  «        dd¬¦  «        }|S )Nr   Tr�  )r[  ÚxyxyÚimage_shape)r(   r
   r   rN   r�  r‘  r’  Úto_denseÚ
from_denser   r¬  r‚   rƒ   r   )r[  r©  r›  Úcompact_candidateÚ
union_maskÚdense_candidateÚdense_unions          r   Ú_update_mask_candidater³  ›  s  € õ
 �%�Ñ%Ô%ð 
Ý ¥¨iÑ8Ô8ÐÝ”]×)Ò)ÝŒN˜E )Ô,×5Ò5Ñ7Ô7Ð9J×9SÒ9SÑ9UÔ9UÐVÑWÔWØØð *ñ 
ô 
ˆ
õ
 Ô%ØÝ˜jÑ)Ô)ØÔ)ð
ñ 
ô 
ð 	
õ
 �3œ;¥sÔ+¨YÑ7Ô7€OÝ$&¤M×$8Ò$8Ý
Œ˜˜iÔ(¨/Ð:Ñ;Ô;ØØð %9ñ %ô %€Kð
 Ðr   c                óø  — g }| dd…df         }|                      ¦   «         }t          |¦  «        dk    �rCt          |d         ¦  «        }|dd…         }t          |¦  «        dk    r|                     |g¦  «         nú||g         }|g}	t          |¦  «        dk    r²t	          ||         ||¦  «                             ¦   «         }
|
|k    }|                     ¦   «         snn||         }t          |||¦  «        }|	                     t          j
        |¦  «                             ¦   «         ¦  «         ||          }t          |¦  «        dk    °²|                     |	¦  «         t          |¦  «        dk    �°C|S )zGGroup masks by exact overlap while updating the merged candidate union.NrÒ   r   r®   )ra  r—   r	  rQ  rY  r�  rš   r³  r“  rN   rs  r”  )rZ  r[  rD   rU   r•  r|  r–  r—  r©  Úmerge_grouprí   rš  r›  s                r   Ú_greedy_nmm_via_mask_candidater¶  µ  sr  € ð %'€LØ˜˜˜˜A˜Ô€FØ�NŠNÑÔ€EÝ
ˆe‰*Œ*�qŠ.‰.Ý�%˜”)‰nŒnˆØ�c�r�c”
ˆÝˆu‰:Œ:˜Š?ˆ?Ø×Ò  Ñ&Ô&Ð&ØØ˜3˜%”Lˆ	Ø�eˆÝ�%‰jŒj˜1ŠnˆnÝ! %¨¤,°	¸>ÑJÔJ×RÒRÑTÔTˆDØ" mÒ3ˆOØ"×&Ò&Ñ(Ô(ð ØØ˜oÔ.ˆIÝ.¨u°iÀÑKÔKˆIØ×Ò�rœw yÑ1Ô1×8Ò8Ñ:Ô:Ñ;Ô;Ð;Ø˜?Ð*Ô+ˆEõ �%‰jŒj˜1Šnˆnð 	×Ò˜KÑ(Ô(Ð(õ# ˆe‰*Œ*�qŠ.‰.ð$ Ðr   c                ó&   — t          | |||¦  «        S r   )r¶  )rZ  r[  rD   rU   s       r   r¢  r¢  Ô  s   € õ *Ø�U˜M¨>ñô ð r   r£  ú1Callable[[npt.NDArray[np.int_]], list[list[int]]]c                óø  ‡— | j         d         dk    r?t          j        t          | ¦  «        t          ¬¦  «        Šˆfd„ |‰¦  «        D ¦   «         S | dd…df         }g }t          j        |¦  «        D ][}t          j        ||k    ¦  «        d         } ||¦  «        D ]/}|                     ||                              ¦   «         ¦  «         Œ0Œ\|D ]'}t          |¦  «        dk    rt          d|› �¦  «        ‚Œ(|S )a“  Dispatch NMM grouping per class, then translate local indices back to
    the global row positions of ``predictions``.

    ``group_within(global_indices)`` must return merge groups expressed in
    terms of *positions inside `global_indices`*, not absolute row positions.
    When ``predictions`` has no class column, a single pass over all rows is
    performed instead of per-category iteration.
    rH   r_  rx   c                óD   •— g | ]}‰|                               ¦   «         ‘ŒS r:   )r”  )Ú.0ÚgrouprŸ  s     €r   ú
<listcomp>z/_non_max_merge_per_category.<locals>.<listcomp>í  s7   ø€ ð 
ð 
ð 
Ø/4ˆN˜5Ô!×(Ò(Ñ*Ô*ð
ð 
ð 
r   Nr   z6Empty group detected when non-max-merging detections: )
r�   rN   Úaranger—   r	  Úuniquer}   rQ  r”  r+   )	rZ  r£  Úcategory_idsr•  Úcategory_idÚcurr_indicesÚlocal_grouprµ  rŸ  s	           @r   r¥  r¥  ß  sM  ø€ ð Ô˜Ô˜qÒ Ð Ýœ¥3 {Ñ#3Ô#3½3Ð?Ñ?Ô?ˆð
ð 
ð 
ð 
Ø8D¸À^Ñ8TÔ8Tð
ñ 
ô 
ð 	
ð ˜q˜q˜q !˜tÔ$€LØ$&€LÝ”y Ñ.Ô.ð Dð DˆÝ”x °Ò ;Ñ<Ô<¸QÔ?ˆØ'˜<¨Ñ5Ô5ð 	Dð 	DˆKØ×Ò ¨[Ô 9× @Ò @Ñ BÔ BÑCÔCÐCÐCð	Dð $ð ð ˆÝˆ{ÑÔ˜qÒ Ð ÝØWÈÐWÐWñô ð ð !ð Ðr   c                óV  — g }| dd…df         }|                      ¦   «         }t          |¦  «        dk    rót          |d         ¦  «        }|dd…         }t          |¦  «        dk    r|                     |g¦  «         nªt	          | |         dd…dd…f         | ||dz   …dd…f         |¦  «                             ¦   «         }||k    }|gt          j        ||         ¦  «                             ¦   «         ¢}	|                     |	¦  «         ||          }t          |¦  «        dk    °ó|S )a¦  
    Apply greedy version of non-maximum merging to avoid detecting too many
    overlapping bounding boxes for a given object.

    Args:
        predictions: An array of shape `(n, 5)` containing
            the bounding boxes coordinates in format `[x1, y1, x2, y2]`
            and the confidence scores.
        iou_threshold: The intersection-over-union threshold
            to use for non-maximum suppression. Defaults to 0.5.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of boxes (e.g., IoU, IoS).

    Returns:
        Groups of prediction indices to be merged.
            Each group may have 1 or more elements.
    NrÒ   r   r®   rH   )	ra  r—   r	  rQ  r�   r�  rN   rs  r”  )
rZ  rD   rU   r•  r|  r–  r—  rí   rš  rµ  s
             r   Ú_group_overlapping_boxesrÅ     s=  € ð, %'€LØ˜˜˜˜A˜Ô€FØ�NŠNÑÔ€EÝ
ˆe‰*Œ*�qŠ.ˆ.Ý�%˜”)‰nŒnˆØ�c�r�c”
ˆÝˆu‰:Œ:˜Š?ˆ?Ø×Ò  Ñ&Ô&Ð&ØÝØ˜Ô˜q˜q˜q " 1 "˜uÔ%Ø˜˜c A™g˜ r¨ rÐ)Ô*Øñ
ô 
÷ Š'‰)Œ)ð	 	ð
  -Ò/ˆØÐF�RœW U¨?Ô%;Ñ<Ô<×CÒCÑEÔEÐFˆØ×Ò˜KÑ(Ô(Ð(Ø�Ð&Ô'ˆõ ˆe‰*Œ*�qŠ.ˆ.ð Ðr   c                óV   ‡ ‡‡— t          ‰¦  «         dˆˆˆ fd„}t          ‰ |¦  «        S )aã  
    Apply greedy version of non-maximum merging per category to avoid detecting
    too many overlapping bounding boxes for a given object.

    Args:
        predictions: An array of shape `(n, 5)` or `(n, 6)`
            containing the bounding boxes coordinates in format `[x1, y1, x2, y2]`,
            the confidence scores and class_ids. Omit class_id column to allow
            detections of different classes to be merged.
        iou_threshold: The intersection-over-union threshold
            to use for non-maximum suppression. Defaults to 0.5.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of boxes (e.g., IoU, IoS).

    Returns:
        list[list[int]]: Groups of prediction indices be merged.
            Each group may have 1 or more elements.

    Raises:
        ValueError: If `iou_threshold` is not within the closed range
            from `0` to `1`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> predictions = np.array([
        ...     [0, 0, 4, 4, 0.9, 0],
        ...     [0, 0, 4, 4, 0.8, 0],
        ... ])
        >>> sv.box_non_max_merge(predictions, iou_threshold=0.5)
        [[0, 1]]

        ```
    rŸ  r   r   rŠ  c                ó2   •— t          ‰|          ‰‰¦  «        S r   )rÅ  )rŸ  rD   rU   rZ  s    €€€r   r£  z'box_non_max_merge.<locals>.group_withinU  s!   ø€ Ý'Ø˜Ô'¨¸ñ
ô 
ð 	
r   r¤  )rK   r¥  )rZ  rD   rU   r£  s   ``` r   Úbox_non_max_mergerÈ  +  sP   øøø€ õP ˜MÑ*Ô*Ð*ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
õ
 ' {°LÑAÔAÐAr   Úoriented_boxesc                ó.  — t          |¦  «         d| fd|ffD ]Õ\  }}|dk    r6|j        dk    s|j        d         dvrt          d|› d|j        › d�¦  «        ‚ŒA|j        d	k    r.|j        dd
…         dk    rt          d|› d|j        › d�¦  «        ‚|j        dk    r,|j        d         dk    rt          d|› d|j        › d�¦  «        ‚|j        dvrt          d|› d|j        › d�¦  «        ‚ŒÖt	          | ¦  «        t	          |¦  «        k    r0t          dt	          | ¦  «        › dt	          |¦  «        › d�¦  «        ‚t          | ¦  «        \  }}}||         }t          |||¦  «        }	t          |	||¦  «        }
|
|                     ¦   «                  }|S )už  
    Perform Non-Maximum Suppression on oriented bounding box predictions.

    Overlap is computed via :func:`oriented_box_iou_batch` on the four
    corners of each box, so detections whose axis-aligned bounding boxes
    overlap heavily but whose oriented bodies do not are kept â€” unlike
    :func:`box_non_max_suppression`, which would suppress them.

    Args:
        predictions: An array of object detection predictions in the
            format ``(x_min, y_min, x_max, y_max, score)`` or
            ``(x_min, y_min, x_max, y_max, score, class)``. Shape ``(N, 5)``
            or ``(N, 6)``. Only the score (column 4) and optional class
            (column 5) are read; the axis-aligned coordinates are not used.
        oriented_boxes: Array of shape ``(N, 4, 2)`` containing the four
            ``(x, y)`` corners of each oriented box, aligned with
            ``predictions`` row-by-row.
        iou_threshold: The intersection-over-union threshold to use for
            non-maximum suppression.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of oriented boxes (e.g., IoU, IoS).

    Returns:
        A boolean array of shape ``(N,)`` indicating which predictions
            to keep after non-maximum suppression.

    Raises:
        ValueError: If ``iou_threshold`` is not within the closed range
            from 0 to 1.
        ValueError: If ``predictions`` and ``oriented_boxes`` have
            mismatched lengths or invalid shapes.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> oriented_boxes = np.array([
        ...     [[10, 10], [50, 10], [50, 30], [10, 30]],
        ...     [[11, 11], [51, 11], [51, 31], [11, 31]],
        ... ], dtype=np.float32)
        >>> predictions = np.array([
        ...     [10, 10, 50, 30, 0.9, 0],
        ...     [11, 11, 51, 31, 0.8, 0],
        ... ], dtype=np.float32)
        >>> keep = sv.oriented_box_non_max_suppression(
        ...     predictions=predictions,
        ...     oriented_boxes=oriented_boxes,
        ...     iou_threshold=0.5,
        ... )
        >>> keep
        array([ True, False])

        ```
    rZ  rÉ  r•   rH   ©r_  é   rÓ   rÔ   ú; expected (N, 5) or (N, 6).r–   NrÑ   rÕ   rÖ   r×   rØ   rÙ   rÚ   úB`predictions` and `oriented_boxes` must have the same length, got rK  )	rK   rÛ   r�   r+   r—   rt  r  rz  ra  )rZ  rÉ  rD   rU   rã   rä   re  rþ   rf  rí   rg  r  s               r   Ú oriented_box_non_max_suppressionrÏ  ]  s=  € õx ˜MÑ*Ô*Ð*Ø$ kÐ2Ð5EÀ~Ð4VÐWð ð ‰	ˆˆcØ�=Ò Ð ØŒx˜1Š}ˆ} ¤	¨!¤°FÐ :Ð :Ý ØQ˜ÐQÐQ¨#¬)ÐQÐQÐQñô ð ð ØŒ8�qŠ=ˆ=˜SœY q r rœ]¨fÒ4Ð4ÝðU�Dð Uð U c¤ið Uð Uð Uñô ð ð ŒX˜Š]ˆ]˜sœy¨œ|¨qÒ0Ð0Ýð?�Dð ?ð ? c¤ið ?ð ?ð ?ñô ð ð ŒX˜VÐ#Ð#ÝØW�DÐWÐWÈ3Ì9ÐWÐWÐWñô ð ð $õ ˆ;ÑÔ�3˜~Ñ.Ô.Ò.Ð.ÝðAÝ�{Ñ#Ô#ðAð AÝ*-¨nÑ*=Ô*=ðAð Að Añ
ô 
ð 	
õ !=¸[Ñ IÔ IÑ€J��:Ø# JÔ/€Nå! .°.À.ÑQÔQ€DÝ$ T¨:°}ÑEÔE€DØ$(¨×);Ò);Ñ)=Ô)=Ô$>€FØ€Mr   c                ó8  — g }| dd…df         }|                      ¦   «         }t          |¦  «        dk    rät          |d         ¦  «        }|dd…         }t          |¦  «        dk    r|                     |g¦  «         n›t	          ||         ||         d         |¦  «                             ¦   «         }||k    }	|gt          j        ||	         ¦  «                             ¦   «         ¢}
|                     |
¦  «         ||	          }t          |¦  «        dk    °ä|S )z�
    Greedy non-maximum merging on oriented boxes. Mirrors
    :func:`_group_overlapping_boxes` but uses :func:`oriented_box_iou_batch`.
    NrÒ   r   r®   rŒ  )	ra  r—   r	  rQ  r  r�  rN   rs  r”  )rZ  rÉ  rD   rU   r•  r|  r–  r—  rí   rš  rµ  s              r   Ú!_group_overlapping_oriented_boxesrÑ  ½  s   € ð %'€LØ˜˜˜˜A˜Ô€FØ�NŠNÑÔ€EÝ
ˆe‰*Œ*�qŠ.ˆ.Ý�%˜”)‰nŒnˆØ�c�r�c”
ˆÝˆu‰:Œ:˜Š?ˆ?Ø×Ò  Ñ&Ô&Ð&ØÝ%Ø˜5Ô!Ø˜3Ô 	Ô*Øñ
ô 
÷ Š'‰)Œ)ð	 	ð
  -Ò/ˆØÐF�RœW U¨?Ô%;Ñ<Ô<×CÒCÑEÔEÐFˆØ×Ò˜KÑ(Ô(Ð(Ø�Ð&Ô'ˆõ ˆe‰*Œ*�qŠ.ˆ.ð Ðr   c                ó¶  ‡ ‡‡‡— d‰ fd‰ffD ]Õ\  }}|dk    r6|j         dk    s|j        d         dvrt          d|› d|j        › d�¦  «        ‚ŒA|j         d	k    r.|j        dd
…         dk    rt          d|› d|j        › d�¦  «        ‚|j         dk    r,|j        d         dk    rt          d|› d|j        › d�¦  «        ‚|j         dvrt          d|› d|j        › d�¦  «        ‚ŒÖt          ‰ ¦  «        t          ‰¦  «        k    r0t          dt          ‰ ¦  «        › dt          ‰¦  «        › d�¦  «        ‚t	          ‰¦  «         dˆˆˆˆ fd„}t          ‰ |¦  «        S )uä  
    Perform Non-Maximum Merging on oriented bounding box predictions,
    grouped per category.

    Mirrors :func:`box_non_max_merge` but uses oriented-box IoU, so groups
    of rotated detections sharing the same body â€” rather than the same
    axis-aligned bounding box â€” are merged.

    Args:
        predictions: An array of shape ``(n, 5)`` or ``(n, 6)`` containing
            the axis-aligned coordinates ``[x1, y1, x2, y2]``, confidence
            scores, and optionally class ids. Only the score and optional
            class are used by the grouping logic; overlap is computed on
            ``oriented_boxes``.
        oriented_boxes: Array of shape ``(N, 4, 2)`` containing the four
            ``(x, y)`` corners of each oriented box.
        iou_threshold: The intersection-over-union threshold to use for
            non-maximum merging.
        overlap_metric: Metric used to compute the degree of overlap
            between pairs of oriented boxes (e.g., IoU, IoS).

    Returns:
        Groups of prediction indices to be merged. Each group may have 1
            or more elements.

    Raises:
        ValueError: If ``iou_threshold`` is not within the closed range
            from 0 to 1.
        ValueError: If ``predictions`` and ``oriented_boxes`` have
            mismatched lengths or invalid shapes.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> oriented_boxes = np.array([
        ...     [[10, 10], [50, 10], [50, 30], [10, 30]],
        ...     [[11, 11], [51, 11], [51, 31], [11, 31]],
        ... ], dtype=np.float32)
        >>> predictions = np.array([
        ...     [10, 10, 50, 30, 0.9, 0],
        ...     [11, 11, 51, 31, 0.8, 0],
        ... ], dtype=np.float32)
        >>> groups = sv.oriented_box_non_max_merge(
        ...     predictions=predictions,
        ...     oriented_boxes=oriented_boxes,
        ...     iou_threshold=0.5,
        ... )
        >>> len(groups)
        1

        ```
    rZ  rÉ  r•   rH   rË  rÓ   rÔ   rÍ  r–   NrÑ   rÕ   rÖ   r×   rØ   rÙ   rÚ   rÎ  rK  rŸ  r   r   rŠ  c                ó@   •— t          ‰|          ‰|          ‰‰¦  «        S r   )rÑ  )rŸ  rD   rÉ  rU   rZ  s    €€€€r   r£  z0oriented_box_non_max_merge.<locals>.group_within3  s+   ø€ Ý0Ø˜Ô'Ø˜>Ô*ØØñ	
ô 
ð 	
r   r¤  )rÛ   r�   r+   r—   rK   r¥  )rZ  rÉ  rD   rU   rã   rä   r£  s   ````   r   Úoriented_box_non_max_mergerÔ  Ü  s%  øøøø€ ðv % kÐ2Ð5EÀ~Ð4VÐWð ð ‰	ˆˆcØ�=Ò Ð ØŒx˜1Š}ˆ} ¤	¨!¤°FÐ :Ð :Ý ØQ˜ÐQÐQ¨#¬)ÐQÐQÐQñô ð ð ØŒ8�qŠ=ˆ=˜SœY q r rœ]¨fÒ4Ð4ÝðU�Dð Uð U c¤ið Uð Uð Uñô ð ð ŒX˜Š]ˆ]˜sœy¨œ|¨qÒ0Ð0Ýð?�Dð ?ð ? c¤ið ?ð ?ð ?ñô ð ð ŒX˜VÐ#Ð#ÝØW�DÐWÐWÈ3Ì9ÐWÐWÐWñô ð ð $õ ˆ;ÑÔ�3˜~Ñ.Ô.Ò.Ð.ÝðAÝ�{Ñ#Ô#ðAð AÝ*-¨nÑ*=Ô*=ðAð Að Añ
ô 
ð 	
õ ˜MÑ*Ô*Ð*ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
õ ' {°LÑAÔAÐAr   )rD   rE   r   rF   )rC   rL   r*   rL   r   rE   )rR   rS   rT   rS   rU   rA   r   rE   )rs   rt   ru   rt   rU   rA   r   rv   )rs   r�   ru   r�   r‘   r’   r   r“   )rª   rt   r   r“   )rª   rt   r   rt   )rÄ   rt   rÅ   rt   r   rÆ   )rs   rt   ru   rt   rU   r<   r   rÏ   )r  r   r  r   rU   r<   r   rÏ   )r  r5  r  r5  rU   r<   r   rÏ   )
r  rH  r  rH  rU   r<   rI  r	  r   rÏ   )rZ  rÏ   r[  rH  rD   rE   rU   r<   r\  r	  r   r]  )rZ  rÏ   r[  rH  rk  rE   rU   r<   r\  r	  r   rÏ   )rZ  rÏ   r   rq  )rí   rÏ   rf  rÏ   rD   rE   r   r]  )rk  rE   r   rF   )
rí   rÏ   rf  rÏ   r|  rÏ   rk  rE   r   rÏ   )rZ  rÏ   rD   rE   rU   r<   r   r]  )rZ  rÏ   rk  rE   rU   r<   r   rÏ   )
rZ  rÏ   r[  r]  rD   rE   rU   r<   r   rŠ  )r±   )rZ  rÏ   r[  rH  rD   rE   r�  r   rU   r<   r\  r	  r   rŠ  )r[  rH  r©  rH  r›  r   r   rH  )
rZ  rÏ   r[  rH  rD   rE   rU   r<   r   rŠ  )rZ  rÏ   r£  r¸  r   rŠ  )rZ  rÏ   rD   rE   rU   r<   r   rŠ  )
rZ  rÏ   rÉ  rÏ   rD   rE   rU   r<   r   r]  )
rZ  rÏ   rÉ  rÏ   rD   rE   rU   r<   r   rŠ  ):Ú
__future__r   rM  Úcollections.abcr   r   Úenumr   Útypingr   r   ÚnumpyrN   Únumpy.typingr‚   Úsupervisionr	   rà   Ú"supervision.detection.compact_maskr
   Ú&supervision.detection.utils.convertersr   Úsupervision.utils.internalr   r   r<   rK   rQ   r=   rr   r�   r©   r¾   rÃ   rÎ   r  r4  rG  rY  rj  rp  rt  rz  rm  rn  r†  r‰  rœ  r¨  r³  r¶  r¢  r¥  rÅ  rÈ  rÏ  rÑ  rÔ  r:   r   r   ú<module>rß     sN  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð à #Ð #Ð #Ð #Ð #Ð #Ø :Ð :Ð :Ð :Ð :Ð :Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6ð#
ð #
ð #
ð #
ð #
�Dñ #
ô #
ð #
ðL!
ð !
ð !
ð !
ð !
�Dñ !
ô !
ð !
ðH
ð 
ð 
ð 
ðFð Fð Fð Fð +8Ô*;ðP)ð P)ð P)ð P)ð P)ðl +8Ô*;ðlð lð lð lð lð^dð dð dð dðNJð Jð Jð Jð8ð ð ð ð Xð Xð Xð XðF %2Ô$5ðyCð yCð yCð yCð yCð~ %2Ô$5ðdð dð dð dð dðT %2Ô$5ðA0ð A0ð A0ð A0ð A0ðN %2Ô$5Ø ð	j;ð j;ð j;ð j;ð j;ð` Ø$1Ô$5ØðLCð LCð LCð LCð LCðd Ø$1Ô$5ØðR)ð R)ð R)ð R)ð R)ðj/ð /ð /ð /ð"ð ð ð ð,Uð Uð Uð UðTð Tð Tð Tð4 Ø$1Ô$5ð+ð +ð +ð +ð +ð` Ø$1Ô$5ð4ð 4ð 4ð 4ð 4ðt Ø$1Ô$5ð	6ð 6ð 6ð 6ð 6ðx ð_Bð
 %2Ô$5Øð_Bð _Bð _Bð _Bð _Bð _BðDð ð ð ð: Ø$1Ô$5ð	ð ð ð ð ðD Ø$1Ô$5ð	ð ð ð ð ðð ð ð ðF Ø$1Ô$5ð(ð (ð (ð (ð (ðZ Ø$1Ô$5ð/Bð /Bð /Bð /Bð /Bðj Ø$1Ô$5ð	]ð ]ð ]ð ]ð ]ðF Ø$1Ô$5ð	ð ð ð ð ðD Ø$1Ô$5ð	_Bð _Bð _Bð _Bð _Bð _Bð _Br   