Ë
    ¼Ó^j0  ã                  óè   — d dl mZ d dlmZ d dl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 erd dlmZ d	Z G d
„ de«      Z	 	 	 	 	 	 dd„Zdd„Z	 	 	 	 dd„Zdd„Zej0                  f	 	 	 	 	 dd„Zy)é    )Úannotations)ÚEnum)ÚTYPE_CHECKINGN)ÚORIENTED_BOX_COORDINATES)ÚCompactMask)ÚMetricTarget)Ú
Detections)i   i $  c                  ó    — e Zd ZdZdZdZdZdZy)ÚObjectSizeCategorya¯  
    Enum for object size categories based on area in pixels.

    Small: area < 32^2
    Medium: 32^2 <= area < 96^2
    Large: area >= 96^2

    Example:
        ```pycon
        >>> from supervision.metrics.utils.object_size import ObjectSizeCategory
        >>> ObjectSizeCategory.SMALL.value
        1
        >>> ObjectSizeCategory.MEDIUM.value
        2
        >>> ObjectSizeCategory.LARGE.value
        3

        ```
    éÿÿÿÿé   é   é   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚANYÚSMALLÚMEDIUMÚLARGE© ó    úp/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/metrics/utils/object_size.pyr   r      s   „ ñð( €CØ€EØ€FØ�Er   r   c                óÌ   — |t         j                  k(  rt        | «      S |t         j                  k(  rt	        | «      S |t         j
                  k(  rt        | «      S t        d«      ‚)aq  
    Get the size category of an object. Distinguish based on the metric target.

    Args:
        data: The object data, shaped (N, ...).
        metric_target: Determines whether boxes, masks or
            oriented bounding boxes are used.

    Returns:
        The size category of each object, matching
        the enum values of ObjectSizeCategory. Shaped (N,).

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.metrics.core import MetricTarget
        >>> from supervision.metrics.utils.object_size import get_object_size_category
        >>> xyxy = np.array([
        ...     [0, 0, 10, 10],    # 100 (Small)
        ...     [0, 0, 50, 50],    # 2500 (Medium)
        ...     [0, 0, 100, 100]   # 10000 (Large)
        ... ])
        >>> get_object_size_category(xyxy, MetricTarget.BOXES)
        array([1, 2, 3])

        ```
    úInvalid metric type)r   ÚBOXESÚget_bbox_size_categoryÚMASKSÚget_mask_size_categoryÚORIENTED_BOUNDING_BOXESÚget_obb_size_categoryÚ
ValueError)ÚdataÚmetric_targets     r   Úget_object_size_categoryr&   .   s[   € ð< œ×*Ñ*Ò*Ü% dÓ+Ð+Øœ×*Ñ*Ò*Ü% dÓ+Ð+Øœ×<Ñ<Ò<Ü$ TÓ*Ð*Ü
Ð*Ó
+Ð+r   c                ó  — t        | j                  «      dk7  s| j                  d   dk7  rt        d«      ‚| dd…df   | dd…df   z
  }| dd…df   | dd…df   z
  }||z  }t        j                  |j                  t
        j                  j                  «      }t        \  }}t
        j                  j                  |||k  <   t
        j                  j                  |||k\  ||k  z  <   t
        j                  j                  |||k\  <   |S )aÙ  
    Get the size category of a bounding boxes array.

    Args:
        xyxy: The bounding boxes array shaped (N, 4).

    Returns:
        The size category of each bounding box, matching
        the enum values of ObjectSizeCategory. Shaped (N,).

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.metrics.utils.object_size import get_bbox_size_category
        >>> xyxy = np.array([
        ...     [0, 0, 31, 31],    # 961 (Small)
        ...     [0, 0, 32, 32],    # 1024 (Medium)
        ...     [0, 0, 95, 95],    # 9025 (Medium)
        ...     [0, 0, 96, 96]     # 9216 (Large)
        ... ])
        >>> get_bbox_size_category(xyxy)
        array([1, 2, 2, 3])

        ```
    r   r   é   z$Bounding boxes must be shaped (N, 4)Nr   r   )ÚlenÚshaper#   ÚnpÚfullr   r   ÚvalueÚSIZE_THRESHOLDSr   r   r   )ÚxyxyÚwidthÚheightÚareasÚresultÚSMÚLGs          r   r   r   U   sò   € ô4 ˆ4�:‰:ƒ˜!Ò˜tŸz™z¨!™}°Ò1ÜÐ?Ó@Ð@à’�A�‰J˜ša ˜d™Ñ#€EØ’!�Q�$‰Z˜$šq !˜t™*Ñ$€FØ�F‰N€Eä�W‰W�U—[‘[Ô"4×"8Ñ"8×">Ñ">Ó?€FÜ�F€BˆÜ+×1Ñ1×7Ñ7€Fˆ5�2‰:ÑÜ+=×+DÑ+D×+JÑ+J€FˆE�R‰K˜E B™JÑ'Ñ(Ü,×2Ñ2×8Ñ8€Fˆ5�B‰;ÑØ€Mr   c                ó  — t        | t        «      r| j                  }n:t        | j                  «      dk7  rt        d«      ‚t        j                  | d¬«      }t        j                  |j                  t        j                  j                  «      }t        \  }}t        j                  j                  |||k  <   t        j                  j                  |||k\  ||k  z  <   t        j                  j                  |||k\  <   |S )aõ  
    Get the size category of detection masks.

    Args:
        mask: The mask array shaped (N, H, W), or a
            :class:`~supervision.detection.compact_mask.CompactMask`.

    Returns:
        The size category of each mask, matching
        the enum values of ObjectSizeCategory. Shaped (N,).

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.metrics.utils.object_size import get_mask_size_category
        >>> mask = np.zeros((3, 100, 100), dtype=bool)
        >>> mask[0, 0:10, 0:10] = True   # 100 (Small)
        >>> mask[1, 0:50, 0:50] = True   # 2500 (Medium)
        >>> mask[2, 0:100, 0:100] = True # 10000 (Large)
        >>> get_mask_size_category(mask)
        array([1, 2, 3])

        ```
    r   zMasks must be shaped (N, H, W))r   r   )Úaxis)Ú
isinstancer   Úarear)   r*   r#   r+   Úsumr,   r   r   r-   r.   r   r   r   )Úmaskr2   r3   r4   r5   s        r   r    r    ~   sÉ   € ô6 �$œÔ$Ø—	‘	‰äˆt�z‰z‹?˜aÒÜÐ=Ó>Ð>Ü—‘�t &Ô)ˆä�W‰W�U—[‘[Ô"4×"8Ñ"8×">Ñ">Ó?€FÜ�F€BˆÜ+×1Ñ1×7Ñ7€Fˆ5�2‰:ÑÜ+=×+DÑ+D×+JÑ+J€FˆE�R‰K˜E B™JÑ'Ñ(Ü,×2Ñ2×8Ñ8€Fˆ5�B‰;ÑØ€Mr   c                óà  — t        | j                  «      dk7  s$| j                  d   dk7  s| j                  d   dk7  rt        d«      ‚| dd…dd…df   }| dd…dd…df   }|j                  \  }}}}|j                  \  }}}	}
dt	        j
                  ||z  ||	z  z   ||
z  z   ||z  z   ||z  ||z  z   ||	z  z   ||
z  z   z
  «      z  }t	        j                  |j                  t        j                  j                  «      }t        \  }}t        j                  j                  |||k  <   t        j                  j                  |||k\  ||k  z  <   t        j                  j                  |||k\  <   |S )	að  
    Get the size category of a oriented bounding boxes array.

    Args:
        xyxyxyxy: The bounding boxes array shaped (N, 4, 2).

    Returns:
        The size category of each bounding box, matching
        the enum values of ObjectSizeCategory. Shaped (N,).

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.metrics.utils.object_size import get_obb_size_category
        >>> obb = np.array([
        ...     [[0, 0], [10, 0], [10, 10], [0, 10]],   # 100 (Small)
        ...     [[0, 0], [50, 0], [50, 50], [0, 50]],   # 2500 (Medium)
        ...     [[0, 0], [100, 0], [100, 100], [0, 100]] # 10000 (Large)
        ... ])
        >>> get_obb_size_category(obb)
        array([1, 2, 3])

        ```
    r   r   r(   r   z0Oriented bounding boxes must be shaped (N, 4, 2)Nr   g      à?)r)   r*   r#   ÚTr+   Úabsr,   r   r   r-   r.   r   r   r   )ÚxyxyxyxyÚxÚyÚx1Úx2Úx3Úx4Úy1Úy2Úy3Úy4r2   r3   r4   r5   s                  r   r"   r"   ¨   sl  € ô2 ˆ8�>‰>Ó˜aÒ 8§>¡>°!Ñ#4¸Ò#9¸X¿^¹^ÈAÑ=NÐRSÒ=SÜÐKÓLÐLð 	’’A�q�Ñ€AØ’’A�q�Ñ€AØ—S‘S�N€BˆˆB�Ø—S‘S�N€BˆˆB�Ø”"—&‘&Ø	ˆb‰�2˜‘7Ñ	˜R "™WÑ	$ r¨B¡wÑ	.Ø�‰7�R˜"‘WÑ˜r B™wÑ&¨¨b©Ñ0ñ	2óñ €Eô
 �W‰W�U—[‘[Ô"4×"8Ñ"8×">Ñ">Ó?€FÜ�F€BˆÜ+×1Ñ1×7Ñ7€Fˆ5�2‰:ÑÜ+=×+DÑ+D×+JÑ+J€FˆE�R‰K˜E B™JÑ'Ñ(Ü,×2Ñ2×8Ñ8€Fˆ5�B‰;ÑØ€Mr   c                ó¾  — |t         j                  k(  rt        | j                  «      S |t         j                  k(  r,| j
                  €t        d«      ‚t        | j
                  «      S |t         j                  k(  rY| j                  j                  t        «      €t        d«      ‚t        t        j                  | j                  t           «      «      S t        d«      ‚)aX  
    Get the size category of a detections object.

    Args:
        detections: The detections object.
        metric_target: Determines whether boxes, masks or
            oriented bounding boxes are used.

    Returns:
        The size category of each bounding box, matching
        the enum values of ObjectSizeCategory. Shaped (N,).
    z Detections mask is not availablez4Detections oriented bounding boxes are not availabler   )r   r   r   r/   r   r;   r#   r    r!   r$   Úgetr   r"   r+   Úarray)Ú
detectionsr%   s     r   Úget_detection_size_categoryrN   Ö   sµ   € ð œ×*Ñ*Ò*Ü% j§o¡oÓ6Ð6Øœ×*Ñ*Ò*Ø�?‰?Ð"ÜÐ?Ó@Ð@Ü% j§o¡oÓ6Ð6Øœ×<Ñ<Ò<Ø�?‰?×ÑÔ7Ó8Ð@ÜÐSÓTÐTÜ$Ü�H‰H�Z—_‘_Ô%=Ñ>Ó?ó
ð 	
ô Ð*Ó
+Ð+r   )r$   znpt.NDArrayr%   r   Úreturnúnpt.NDArray[np.int_])r/   únpt.NDArray[np.float32]rO   rP   )r;   z#npt.NDArray[np.bool_] | CompactMaskrO   rP   )r?   rQ   rO   rP   )rM   r	   r%   r   rO   rP   )Ú
__future__r   Úenumr   Útypingr   Únumpyr+   Únumpy.typingÚnptÚsupervision.configr   Ú"supervision.detection.compact_maskr   Úsupervision.metrics.corer   Úsupervision.detection.corer	   r.   r   r&   r   r    r"   r   rN   r   r   r   ú<module>r\      s�   ðÝ "å Ý  ã Ý å 7Ý :Ý 1áÝ5à €ô˜ô ð6$,Ø
ð$,Ø&2ð$,àó$,óN&ðR'Ø
-ð'àó'óT+ð^ ;G×:LÑ:Lð,Øð,Ø+7ð,àô,r   