§
    ezni@>  ã                   óÔ   — d dl mZ d dlmZ d dlmZ d dlmZ d dlZ	ddl
mZmZmZmZmZmZmZ d„ Z ed	¦  «        Z ed
¦  «        Zg d¢ZdZ G d„ d¦  «        Z G d„ d¦  «        ZdS )é    )Úabc)Úrepeat)ÚNumber)ÚListNé   )Ú	ltwh2xywhÚ	ltwh2xyxyÚresample_segmentsÚ	xywh2ltwhÚ	xywh2xyxyÚ	xyxy2ltwhÚ	xyxy2xywhc                 ó   ‡ — ˆ fd„}|S )zFrom PyTorch internals.c                 óv   •— t          | t          j        ¦  «        r| nt          t	          | ‰¦  «        ¦  «        S )z2Parse bounding boxes format between XYWH and LTWH.)Ú
isinstancer   ÚIterableÚtupler   )ÚxÚns    €úz/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/utils/instance.pyÚparsez_ntuple.<locals>.parse   s.   ø€ å˜q¥#¤,Ñ/Ô/ÐHˆqˆqµU½6À!ÀQ¹<¼<Ñ5HÔ5HÐHó    © )r   r   s   ` r   Ú_ntupler      s(   ø€ ðIð Ið Ið Ið Ið €Lr   é   é   )ÚxyxyÚxywhÚltwh)ÚBboxesc                   óp   — e Zd ZdZddd„Zd„ Zd„ Zd„ Zd	„ Zd
„ Z	e
dded          dd fd„¦   «         Zdd„ZdS )r    aÔ  
    A class for handling bounding boxes.

    The class supports various bounding box formats like 'xyxy', 'xywh', and 'ltwh'.
    Bounding box data should be provided in numpy arrays.

    Attributes:
        bboxes (numpy.ndarray): The bounding boxes stored in a 2D numpy array.
        format (str): The format of the bounding boxes ('xyxy', 'xywh', or 'ltwh').

    Note:
        This class does not handle normalization or denormalization of bounding boxes.
    r   ÚreturnNc                 óÐ   — |t           v sJ d|› dt           › �¦   «         ‚|j        dk    r|ddd…f         n|}|j        dk    sJ ‚|j        d         dk    sJ ‚|| _        || _        dS )zJInitializes the Bboxes class with bounding box data in a specified format.úInvalid bounding box format: ú, format must be one of r   Nr   r   )Ú_formatsÚndimÚshapeÚbboxesÚformat)Úselfr)   r*   s      r   Ú__init__zBboxes.__init__1   sŠ   € à�Ð!Ð!Ð!Ð#mÀ6Ð#mÐ#mÕckÐ#mÐ#mÑ!Ô!Ð!Ø$*¤K°1Ò$4Ð$4�˜˜a˜a˜a˜”�¸&ˆØŒ{˜aÒÐÐÐØŒ|˜AŒ !Ò#Ð#Ð#Ð#ØˆŒØˆŒˆˆr   c                 ó<  — |t           v sJ d|› dt           › �¦   «         ‚| j        |k    rdS | j        dk    r|dk    rt          nt          }n4| j        dk    r|dk    rt          nt
          }n|dk    rt          nt          } || j        ¦  «        | _        || _        dS )z6Converts bounding box format from one type to another.r$   r%   Nr   r   )	r&   r*   r   r   r   r   r	   r   r)   )r+   r*   Úfuncs      r   ÚconvertzBboxes.convert;   s´   € à�Ð!Ð!Ð!Ð#mÀ6Ð#mÐ#mÕckÐ#mÐ#mÑ!Ô!Ð!ØŒ;˜&Ò Ð ØˆFØŒ[˜FÒ"Ð"Ø &¨&Ò 0Ð 0•9�9µiˆDˆDØŒ[˜FÒ"Ð"Ø &¨&Ò 0Ð 0•9�9µiˆDˆDà &¨&Ò 0Ð 0•9�9µiˆDØ�d˜4œ;Ñ'Ô'ˆŒØˆŒˆˆr   c                 óº   — |                       d¦  «         | j        dd…df         | j        dd…df         z
  | j        dd…df         | j        dd…df         z
  z  S )zReturn box areas.r   Nr   r   é   r   )r/   r)   ©r+   s    r   ÚareaszBboxes.areasI   sj   € à�Š�VÑÔÐØ”˜A˜A˜A˜q˜DÔ! D¤K°°°°1°Ô$5Ñ5¸$¼+ÀaÀaÀaÈÀdÔ:KÈdÌkÐZ[ÐZ[ÐZ[Ð]^ÐZ^ÔN_Ñ:_Ñ`Ð`r   c                 ó¬  — t          |t          ¦  «        rt          |¦  «        }t          |t          t          f¦  «        sJ ‚t          |¦  «        dk    sJ ‚| j        dd…dfxx         |d         z  cc<   | j        dd…dfxx         |d         z  cc<   | j        dd…dfxx         |d         z  cc<   | j        dd…dfxx         |d         z  cc<   dS )zZ
        Args:
            scale (tuple | list | int): the scale for four coords.
        r   Nr   r   r   r1   ©r   r   Ú	to_4tupler   ÚlistÚlenr)   )r+   Úscales     r   Úmulz
Bboxes.mul^   sþ   € õ
 �e�VÑ$Ô$ð 	%Ý˜eÑ$Ô$ˆEÝ˜%¥%­ Ñ/Ô/Ð/Ð/Ð/Ý�5‰zŒz˜QŠˆˆˆØŒ�A�A�A�q�DÐÐÔ˜U 1œXÑ%ÐÐÑØŒ�A�A�A�q�DÐÐÔ˜U 1œXÑ%ÐÐÑØŒ�A�A�A�q�DÐÐÔ˜U 1œXÑ%ÐÐÑØŒ�A�A�A�q�DÐÐÔ˜U 1œXÑ%ÐÐÑÐÐr   c                 ó¬  — t          |t          ¦  «        rt          |¦  «        }t          |t          t          f¦  «        sJ ‚t          |¦  «        dk    sJ ‚| j        dd…dfxx         |d         z  cc<   | j        dd…dfxx         |d         z  cc<   | j        dd…dfxx         |d         z  cc<   | j        dd…dfxx         |d         z  cc<   dS )z\
        Args:
            offset (tuple | list | int): the offset for four coords.
        r   Nr   r   r   r1   r5   )r+   Úoffsets     r   Úaddz
Bboxes.addl   s  € õ
 �f�fÑ%Ô%ð 	'Ý˜vÑ&Ô&ˆFÝ˜&¥5­$ -Ñ0Ô0Ð0Ð0Ð0Ý�6‰{Œ{˜aÒÐÐÐØŒ�A�A�A�q�DÐÐÔ˜V AœYÑ&ÐÐÑØŒ�A�A�A�q�DÐÐÔ˜V AœYÑ&ÐÐÑØŒ�A�A�A�q�DÐÐÔ˜V AœYÑ&ÐÐÑØŒ�A�A�A�q�DÐÐÔ˜V AœYÑ&ÐÐÑÐÐr   c                 ó*   — t          | j        ¦  «        S )zReturn the number of boxes.©r8   r)   r2   s    r   Ú__len__zBboxes.__len__z   ó   € å�4”;ÑÔÐr   r   Ú
boxes_listc                 ó:  — t          |t          t          f¦  «        sJ ‚|s | t          j        d¦  «        ¦  «        S t          d„ |D ¦   «         ¦  «        sJ ‚t          |¦  «        dk    r|d         S  | t          j        d„ |D ¦   «         |¬¦  «        ¦  «        S )aö  
        Concatenate a list of Bboxes objects into a single Bboxes object.

        Args:
            boxes_list (List[Bboxes]): A list of Bboxes objects to concatenate.
            axis (int, optional): The axis along which to concatenate the bounding boxes.
                                   Defaults to 0.

        Returns:
            Bboxes: A new Bboxes object containing the concatenated bounding boxes.

        Note:
            The input should be a list or tuple of Bboxes objects.
        r   c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S ©N)r   r    )Ú.0Úboxs     r   ú	<genexpr>z%Bboxes.concatenate.<locals>.<genexpr>‘   s,   è è € ÐAÐA¨s•:˜c¥6Ñ*Ô*ÐAÐAÐAÐAÐAÐAr   r   c                 ó   — g | ]	}|j         ‘Œ
S r   ©r)   ©rF   Úbs     r   ú
<listcomp>z&Bboxes.concatenate.<locals>.<listcomp>•   s   € Ð"@Ð"@Ð"@° 1¤8Ð"@Ð"@Ð"@r   ©Úaxis)r   r7   r   ÚnpÚemptyÚallr8   Úconcatenate)ÚclsrB   rO   s      r   rS   zBboxes.concatenate~   sª   € õ  ˜*¥t­U mÑ4Ô4Ð4Ð4Ð4Øð 	$Ø�3•r”x ‘{”{Ñ#Ô#Ð#ÝÐAÐA°jÐAÑAÔAÑAÔAÐAÐAÐAåˆz‰?Œ?˜aÒÐØ˜a”=Ð Øˆs•2”>Ð"@Ð"@°ZÐ"@Ñ"@Ô"@ÀtÐLÑLÔLÑMÔMÐMr   c                 óò   — t          |t          ¦  «        r.t          | j        |                              dd¦  «        ¦  «        S | j        |         }|j        dk    sJ d|› d�¦   «         ‚t          |¦  «        S )aƒ  
        Retrieve a specific bounding box or a set of bounding boxes using indexing.

        Args:
            index (int, slice, or np.ndarray): The index, slice, or boolean array to select
                                               the desired bounding boxes.

        Returns:
            Bboxes: A new Bboxes object containing the selected bounding boxes.

        Raises:
            AssertionError: If the indexed bounding boxes do not form a 2-dimensional matrix.

        Note:
            When using boolean indexing, make sure to provide a boolean array with the same
            length as the number of bounding boxes.
        r   éÿÿÿÿr   zIndexing on Bboxes with z failed to return a matrix!)r   Úintr    r)   Úviewr'   )r+   ÚindexrL   s      r   Ú__getitem__zBboxes.__getitem__—   st   € õ$ �e�SÑ!Ô!ð 	:Ý˜$œ+ eÔ,×1Ò1°!°RÑ8Ô8Ñ9Ô9Ð9ØŒK˜ÔˆØŒv˜Š{ˆ{ˆ{ÐY°uÐYÐYÐY‰{Œ{ˆ{Ý�a‰yŒyÐr   )r   ©r"   N©r   )r"   r    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   r/   r3   r:   r=   r@   Úclassmethodr   rS   rZ   r   r   r   r    r    "   s×   € € € € € ðð ðð ð ð ð ðð ð ðað að að*&ð &ð &ð'ð 'ð 'ð ð  ð  ð ðNð N T¨(¤^ð NÀð Nð Nð Nñ „[ðNð0ð ð ð ð ð r   r    c                   óÄ   — e Zd ZdZddd„Zd„ Zed„ ¦   «         Zdd
„Zd„ Z	d„ Z
d„ Zdd„Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zedded          dd fd„¦   «         Zed„ ¦   «         ZdS )Ú	Instancesa  
    Container for bounding boxes, segments, and keypoints of detected objects in an image.

    Attributes:
        _bboxes (Bboxes): Internal object for handling bounding box operations.
        keypoints (ndarray): keypoints(x, y, visible) with shape [N, 17, 3]. Default is None.
        normalized (bool): Flag indicating whether the bounding box coordinates are normalized.
        segments (ndarray): Segments array with shape [N, 1000, 2] after resampling.

    Args:
        bboxes (ndarray): An array of bounding boxes with shape [N, 4].
        segments (list | ndarray, optional): A list or array of object segments. Default is None.
        keypoints (ndarray, optional): An array of keypoints with shape [N, 17, 3]. Default is None.
        bbox_format (str, optional): The format of bounding boxes ('xywh' or 'xyxy'). Default is 'xywh'.
        normalized (bool, optional): Whether the bounding box coordinates are normalized. Default is True.

    Examples:
        ```python
        # Create an Instances object
        instances = Instances(
            bboxes=np.array([[10, 10, 30, 30], [20, 20, 40, 40]]),
            segments=[np.array([[5, 5], [10, 10]]), np.array([[15, 15], [20, 20]])],
            keypoints=np.array([[[5, 5, 1], [10, 10, 1]], [[15, 15, 1], [20, 20, 1]]])
        )
        ```

    Note:
        The bounding box format is either 'xywh' or 'xyxy', and is determined by the `bbox_format` argument.
        This class does not perform input validation, and it assumes the inputs are well-formed.
    Nr   Tr"   c                 ó  — |€g }t          ||¬¦  «        | _        || _        || _        t	          |¦  «        dk    r&t          |¦  «        }t          j        |d¬¦  «        }n t          j        dt          j	        ¬¦  «        }|| _
        dS )zÑ
        Args:
            bboxes (ndarray): bboxes with shape [N, 4].
            segments (list | ndarray): segments.
            keypoints (ndarray): keypoints(x, y, visible) with shape [N, 17, 3].
        N)r)   r*   r   rN   )r   iè  r   )Údtype)r    Ú_bboxesÚ	keypointsÚ
normalizedr8   r
   rP   ÚstackÚzerosÚfloat32Úsegments)r+   r)   rl   rg   Úbbox_formatrh   s         r   r,   zInstances.__init__Ð   s†   € ð ÐØˆHÝ V°KÐ@Ñ@Ô@ˆŒØ"ˆŒØ$ˆŒåˆx‰=Œ=˜1ÒÐå(¨Ñ2Ô2ˆHå”x ¨qÐ1Ñ1Ô1ˆHˆHå”x µB´JÐ?Ñ?Ô?ˆHØ ˆŒˆˆr   c                 ó<   — | j                              |¬¦  «         dS )zConvert bounding box format.©r*   N)rf   r/   )r+   r*   s     r   Úconvert_bboxzInstances.convert_bboxæ   s!   € àŒ×Ò FÐÑ+Ô+Ð+Ð+Ð+r   c                 ó4   — | j                              ¦   «         S )z%Calculate the area of bounding boxes.)rf   r3   r2   s    r   Ú
bbox_areaszInstances.bbox_areasê   s   € ð Œ|×!Ò!Ñ#Ô#Ð#r   Fc                 ó  — | j                              ||||f¬¦  «         |rdS | j        dxx         |z  cc<   | j        dxx         |z  cc<   | j        �,| j        dxx         |z  cc<   | j        dxx         |z  cc<   dS dS )zHThis might be similar with denormalize func but without normalized sign.©r9   N©.r   ©.r   )rf   r:   rl   rg   )r+   Úscale_wÚscale_hÚ	bbox_onlys       r   r9   zInstances.scaleï   s¿   € àŒ×Ò ¨°'¸7ÐCÐÑDÔDÐDØð 	ØˆFØŒ�fÐÐÔ Ñ(ÐÐÑØŒ�fÐÐÔ Ñ(ÐÐÑØŒ>Ð%ØŒN˜6Ð"Ð"Ô" gÑ-Ð"Ð"Ñ"ØŒN˜6Ð"Ð"Ô" gÑ-Ð"Ð"Ñ"Ð"Ð"ð &Ð%r   c                 ó  — | j         sdS | j                             ||||f¬¦  «         | j        dxx         |z  cc<   | j        dxx         |z  cc<   | j        �*| j        dxx         |z  cc<   | j        dxx         |z  cc<   d| _         dS )zHDenormalizes boxes, segments, and keypoints from normalized coordinates.Nrt   ru   rv   F©rh   rf   r:   rl   rg   ©r+   ÚwÚhs      r   ÚdenormalizezInstances.denormalizeú   s½   € àŒð 	ØˆFØŒ×Ò  1 a¨˜|ÐÑ,Ô,Ð,ØŒ�fÐÐÔ Ñ"ÐÐÑØŒ�fÐÐÔ Ñ"ÐÐÑØŒ>Ð%ØŒN˜6Ð"Ð"Ô" aÑ'Ð"Ð"Ñ"ØŒN˜6Ð"Ð"Ô" aÑ'Ð"Ð"Ñ"ØˆŒˆˆr   c                 ó2  — | j         rdS | j                             d|z  d|z  d|z  d|z  f¬¦  «         | j        dxx         |z  cc<   | j        dxx         |z  cc<   | j        �*| j        dxx         |z  cc<   | j        dxx         |z  cc<   d| _         dS )zFNormalize bounding boxes, segments, and keypoints to image dimensions.Nr   rt   ru   rv   Tr{   r|   s      r   Ú	normalizezInstances.normalize  sÎ   € àŒ?ð 	ØˆFØŒ×Ò  A¡ q¨1¡u¨a°!©e°Q¸±UÐ;ÐÑ<Ô<Ð<ØŒ�fÐÐÔ Ñ"ÐÐÑØŒ�fÐÐÔ Ñ"ÐÐÑØŒ>Ð%ØŒN˜6Ð"Ð"Ô" aÑ'Ð"Ð"Ñ"ØŒN˜6Ð"Ð"Ô" aÑ'Ð"Ð"Ñ"ØˆŒˆˆr   c                 ó   — | j         r
J d¦   «         ‚| j                             ||||f¬¦  «         | j        dxx         |z  cc<   | j        dxx         |z  cc<   | j        �,| j        dxx         |z  cc<   | j        dxx         |z  cc<   dS dS )z!Handle rect and mosaic situation.z1you should add padding with absolute coordinates.)r<   ru   rv   N)rh   rf   r=   rl   rg   )r+   ÚpadwÚpadhs      r   Úadd_paddingzInstances.add_padding  sÉ   € à”?ÐWÐWÐ$WÑWÔWÐ"ØŒ×Ò  t¨T°4Ð 8ÐÑ9Ô9Ð9ØŒ�fÐÐÔ Ñ%ÐÐÑØŒ�fÐÐÔ Ñ%ÐÐÑØŒ>Ð%ØŒN˜6Ð"Ð"Ô" dÑ*Ð"Ð"Ñ"ØŒN˜6Ð"Ð"Ô" dÑ*Ð"Ð"Ñ"Ð"Ð"ð &Ð%r   c                 óâ   — t          | j        ¦  «        r| j        |         n| j        }| j        �| j        |         nd}| j        |         }| j        j        }t          ||||| j        ¬¦  «        S )aB  
        Retrieve a specific instance or a set of instances using indexing.

        Args:
            index (int, slice, or np.ndarray): The index, slice, or boolean array to select
                                               the desired instances.

        Returns:
            Instances: A new Instances object containing the selected bounding boxes,
                       segments, and keypoints if present.

        Note:
            When using boolean indexing, make sure to provide a boolean array with the same
            length as the number of instances.
        N)r)   rl   rg   rm   rh   )r8   rl   rg   r)   rf   r*   rc   rh   )r+   rY   rl   rg   r)   rm   s         r   rZ   zInstances.__getitem__  s|   € õ  ,/¨t¬}Ñ+=Ô+=ÐP�4”= Ô'Ð'À4Ä=ˆØ-1¬^Ð-G�D”N 5Ô)Ð)ÈTˆ	Ø”˜UÔ#ˆØ”lÔ)ˆÝØØØØ#Ø”ð
ñ 
ô 
ð 	
r   c                 óª  — | j         j        dk    ri| j        dd…df                              ¦   «         }| j        dd…df                              ¦   «         }||z
  | j        dd…df<   ||z
  | j        dd…df<   n || j        dd…df         z
  | j        dd…df<   || j        d         z
  | j        d<   | j        �|| j        d         z
  | j        d<   dS dS )zLFlips the coordinates of bounding boxes, segments, and keypoints vertically.r   Nr   r1   rv   ©rf   r*   r)   Úcopyrl   rg   )r+   r~   Úy1Úy2s       r   ÚflipudzInstances.flipud8  óó   € àŒ<Ô &Ò(Ð(Ø”˜Q˜Q˜Q ˜TÔ"×'Ò'Ñ)Ô)ˆBØ”˜Q˜Q˜Q ˜TÔ"×'Ò'Ñ)Ô)ˆBØ ! B¡ˆDŒK˜˜˜˜1˜ÑØ ! B¡ˆDŒK˜˜˜˜1˜ÑÐà ! D¤K°°°°1°Ô$5Ñ 5ˆDŒK˜˜˜˜1˜ÑØ ! D¤M°&Ô$9Ñ 9ˆŒ�fÑØŒ>Ð%Ø%&¨¬¸Ô)?Ñ%?ˆDŒN˜6Ñ"Ð"Ð"ð &Ð%r   c                 óª  — | j         j        dk    ri| j        dd…df                              ¦   «         }| j        dd…df                              ¦   «         }||z
  | j        dd…df<   ||z
  | j        dd…df<   n || j        dd…df         z
  | j        dd…df<   || j        d         z
  | j        d<   | j        �|| j        d         z
  | j        d<   dS dS )zCReverses the order of the bounding boxes and segments horizontally.r   Nr   r   ru   rˆ   )r+   r}   Úx1Úx2s       r   ÚfliplrzInstances.fliplrE  r�   r   c                 ó°  — | j         j        }|                      d¬¦  «         | j        dd…ddgf                              d|¦  «        | j        dd…ddgf<   | j        dd…ddgf                              d|¦  «        | j        dd…ddgf<   |dk    r|                      |¬¦  «         | j        d                              d|¦  «        | j        d<   | j        d	                              d|¦  «        | j        d	<   | j        �T| j        d                              d|¦  «        | j        d<   | j        d	                              d|¦  «        | j        d	<   dS dS )
zUClips bounding boxes, segments, and keypoints values to stay within image boundaries.r   ro   Nr   r   r   r1   ru   rv   )rf   r*   rp   r)   Úcliprl   rg   )r+   r}   r~   Ú
ori_formats       r   r“   zInstances.clipR  s]  € à”\Ô(ˆ
Ø×Ò ÐÑ(Ô(Ð(Ø!%¤¨Q¨Q¨Q°°A°¨YÔ!7×!<Ò!<¸QÀÑ!BÔ!BˆŒ�A�A�A˜˜1�v�IÑØ!%¤¨Q¨Q¨Q°°A°¨YÔ!7×!<Ò!<¸QÀÑ!BÔ!BˆŒ�A�A�A˜˜1�v�IÑØ˜ÒÐØ×Ò ZÐÑ0Ô0Ð0Ø $¤¨fÔ 5× :Ò :¸1¸aÑ @Ô @ˆŒ�fÑØ $¤¨fÔ 5× :Ò :¸1¸aÑ @Ô @ˆŒ�fÑØŒ>Ð%Ø%)¤^°FÔ%;×%@Ò%@ÀÀAÑ%FÔ%FˆDŒN˜6Ñ"Ø%)¤^°FÔ%;×%@Ò%@ÀÀAÑ%FÔ%FˆDŒN˜6Ñ"Ð"Ð"ð &Ð%r   c                 óÜ   — | j         dk    }t          |¦  «        sQ| j        |         | _        t          | j        ¦  «        r| j        |         | _        | j        �| j        |         | _        |S )zƒ
        Remove zero-area boxes, i.e. after clipping some boxes may have zero width or height.

        This removes them.
        r   )rr   rR   rf   r8   rl   rg   )r+   Úgoods     r   Úremove_zero_area_boxesz Instances.remove_zero_area_boxes`  sg   € ð Œ Ò"ˆÝ�4‰yŒyð 	6Øœ<¨Ô-ˆDŒLÝ�4”=Ñ!Ô!ð 4Ø $¤¨dÔ 3�”ØŒ~Ð)Ø!%¤°Ô!5�”Øˆr   c                 ón   — t          || j        j        ¬¦  «        | _        |�|| _        |�	|| _        dS dS )zUpdates instance variables.ro   N)r    rf   r*   rl   rg   )r+   r)   rl   rg   s       r   ÚupdatezInstances.updateo  sA   € å˜f¨T¬\Ô-@ÐAÑAÔAˆŒØÐØ$ˆDŒMØÐ Ø&ˆDŒNˆNˆNð !Ð r   c                 ó*   — t          | j        ¦  «        S )z'Return the length of the instance list.r?   r2   s    r   r@   zInstances.__len__w  rA   r   r   Úinstances_listc                 ó*  — t          |t          t          f¦  «        sJ ‚|s | t          j        d¦  «        ¦  «        S t          d„ |D ¦   «         ¦  «        sJ ‚t          |¦  «        dk    r|d         S |d         j        du}|d         j        j	        }|d         j
        }t          j        d„ |D ¦   «         |¬¦  «        }t          j        d„ |D ¦   «         |¬¦  «        }|r t          j        d„ |D ¦   «         |¬¦  «        nd} | |||||¦  «        S )	a¹  
        Concatenates a list of Instances objects into a single Instances object.

        Args:
            instances_list (List[Instances]): A list of Instances objects to concatenate.
            axis (int, optional): The axis along which the arrays will be concatenated. Defaults to 0.

        Returns:
            Instances: A new Instances object containing the concatenated bounding boxes,
                       segments, and keypoints if present.

        Note:
            The `Instances` objects in the list should have the same properties, such as
            the format of the bounding boxes, whether keypoints are present, and if the
            coordinates are normalized.
        r   c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S rE   )r   rc   )rF   Úinstances     r   rH   z(Instances.concatenate.<locals>.<genexpr>�  s,   è è € ÐRÐR°x•:˜h­	Ñ2Ô2ÐRÐRÐRÐRÐRÐRr   r   Nc                 ó   — g | ]	}|j         ‘Œ
S r   rJ   )rF   Úinss     r   rM   z)Instances.concatenate.<locals>.<listcomp>™  s   € Ð#IÐ#IÐ#I°3 C¤JÐ#IÐ#IÐ#Ir   rN   c                 ó   — g | ]	}|j         ‘Œ
S r   )rl   rK   s     r   rM   z)Instances.concatenate.<locals>.<listcomp>š  s   € Ð&JÐ&JÐ&J°a q¤zÐ&JÐ&JÐ&Jr   c                 ó   — g | ]	}|j         ‘Œ
S r   )rg   rK   s     r   rM   z)Instances.concatenate.<locals>.<listcomp>›  s   € Ð'LÐ'LÐ'L¸¨¬Ð'LÐ'LÐ'Lr   )r   r7   r   rP   rQ   rR   r8   rg   rf   r*   rh   rS   )	rT   r›   rO   Úuse_keypointrm   rh   Ú	cat_boxesÚcat_segmentsÚcat_keypointss	            r   rS   zInstances.concatenate{  s=  € õ$ ˜.­4µ¨-Ñ8Ô8Ð8Ð8Ð8Øð 	$Ø�3•r”x ‘{”{Ñ#Ô#Ð#ÝÐRÐRÀ>ÐRÑRÔRÑRÔRÐRÐRÐRåˆ~ÑÔ !Ò#Ð#Ø! !Ô$Ð$à% aÔ(Ô2¸$Ð>ˆØ$ QÔ'Ô/Ô6ˆØ# AÔ&Ô1ˆ
å”NÐ#IÐ#I¸.Ð#IÑ#IÔ#IÐPTÐUÑUÔUˆ	Ý”~Ð&JÐ&J¸>Ð&JÑ&JÔ&JÐQUÐVÑVÔVˆØ\hÐr�œÐ'LÐ'L¸^Ð'LÑ'LÔ'LÐSWÐXÑXÔXÐXÐnrˆØˆs�9˜l¨M¸;È
ÑSÔSÐSr   c                 ó   — | j         j        S )zReturn bounding boxes.)rf   r)   r2   s    r   r)   zInstances.bboxesž  s   € ð Œ|Ô"Ð"r   )NNr   Tr[   )F)r"   rc   )NNr\   )r]   r^   r_   r`   r,   rp   Úpropertyrr   r9   r   r�   r…   rZ   rŒ   r‘   r“   r—   r™   r@   ra   r   rS   r)   r   r   r   rc   rc   °   sy  € € € € € ðð ð>!ð !ð !ð !ð !ð,,ð ,ð ,ð ð$ð $ñ „Xð$ð	.ð 	.ð 	.ð 	.ð
 ð 
 ð 
 ð
ð 
ð 
ð+ð +ð +ð
ð 
ð 
ð 
ð8@ð @ð @ð@ð @ð @ðGð Gð Gðð ð ð'ð 'ð 'ð 'ð ð  ð  ð ð Tð  T¨¨kÔ):ð  TÀ{ð  Tð  Tð  Tñ „[ð TðD ð#ð #ñ „Xð#ð #ð #r   rc   )Úcollectionsr   Ú	itertoolsr   Únumbersr   Útypingr   ÚnumpyrP   Úopsr   r	   r
   r   r   r   r   r   Ú	to_2tupler6   r&   Ú__all__r    rc   r   r   r   ú<module>r±      s;  ðð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð à dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dðð ð ð ˆG�A‰JŒJ€	ØˆG�A‰JŒJ€	ð
 $Ð#Ð#€à
€ðKð Kð Kð Kð Kñ Kô Kð Kð\q#ð q#ð q#ð q#ð q#ñ q#ô q#ð q#ð q#ð q#r   