§
    à©ºj·  ã            	       óœ   — d dl Zd dlmc mZ 	 d dlZdZn# e$ r dZdZY nw xY wd„ Z	ddej
        deded	efd
„Zdeded	efd„Zded	efd„ZdS )é    NTFc                  ó@   — t           sd} | dz  } t          | ¦  «        ‚dS )z9Check if OpenCV is available and raise informative error.z"Missing dependency: opencv-python
z(Use: pip install faster-coco-eval[extra]N)Úopencv_availableÚImportError)Úmessages    úl/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/faster_coco_eval/extra/utils.pyÚ_check_opencvr      s2   € åð #Ø7ˆØÐ=Ñ=ˆÝ˜'Ñ"Ô"Ð"ð#ð #ó    çš™™™™™¹?ÚmaskÚbboxÚboxes_marginÚreturnc                 óÆ  — t          ¦   «          |\  }}}}||z   }||z   }t          ||z  ¦  «        t          ||z  ¦  «        }
}	||	z  }|dk     rd}||
z  }|dk     rd}||	z  }||
z  }| j        dd…         \  }}||k    r|}||k    r|}t          j        | t          |¦  «        t          |¦  «        …t          |¦  «        t          |¦  «        …f                              t          j        ¦  «        t          j        t          j	        ¦  «        \  }}t          |¦  «        }t          |¦  «        dk    r+t          |¦  «        D ]\  }}|||gz   ||<   Œd„ |D ¦   «         }|S )a  Convert a mask (uint8) to a list of polygons in COCO style.

    Retains contours with at least three vertices, the minimum required for a
    valid COCO polygon.

    Args:
        mask (np.ndarray): The mask image as a numpy array.
        bbox (list): Bounding box of the annotation in the format [x, y, w, h].
        boxes_margin (float, optional): Margin factor to increase the bounding box size. Defaults to 0.1.

    Returns:
        list: List of polygons in COCO format (list of lists of coordinates).
    r   Né   c                 ó|   — g | ]9}|j         d          dk    ¯|                     ¦   «                              ¦   «         ‘Œ:S )r   é   )ÚshapeÚravelÚtolist)Ú.0Ú_cnts     r   ú
<listcomp>z'conver_mask_to_poly.<locals>.<listcomp>I   s<   € ÐQÐQÐQ¨D¸d¼jÈ¼mÈqÒ>PÐ>P�$—*’*‘,”,×%Ò%Ñ'Ô'Ð>PÐ>PÐ>Pr	   )r   Úintr   Úcv2ÚfindContoursÚastypeÚnpÚuint8Ú	RETR_TREEÚCHAIN_APPROX_SIMPLEÚlistÚlenÚ	enumerate)r   r   r   Úx1Úy1ÚwÚhÚx2Úy2Úm_wÚm_hÚmask_hÚmask_wÚcoordsÚ_Úcnt_idxÚcnts                    r   Úconver_mask_to_polyr2      s€  € õ �O„O€Oà�L€BˆˆAˆqØ	ˆa‰€BØ	ˆa‰€Bå�1�|Ñ#Ñ$Ô$¥c¨!¨lÑ*:Ñ&;Ô&;ˆ€CØˆ#�I€BØ	ˆA‚v€vØˆàˆ#�I€BØ	ˆA‚v€vØˆàˆ#�I€BØˆ#�I€Bà”Z   ”^�N€FˆFà	ˆF‚{€{Øˆà	ˆF‚{€{ØˆåÔ Ø�S�‰WŒW•s˜2‘w”wÐ¥ B¡¤­#¨b©'¬'Ð 1Ð1Ô2×9Ò9½"¼(ÑCÔCÝŒÝÔñô �I€FˆAõ �&‰\Œ\€FÝ
ˆ6�{„{�Q‚€Ý% fÑ-Ô-ð 	-ð 	-‰LˆG�SØ! R¨ H™nˆF�7‰OˆOàQÐQ°FÐQÑQÔQˆà€Mr	   Úrlec                 óP   — t          j        | ¦  «        dz  }t          ||¦  «        S )a;  Convert RLE (Run-Length Encoding) to a list of polygons in COCO style.

    Args:
        rle (dict): RLE of the mask image (COCO format).
        bbox (list): Bounding box of the annotation in the format [x, y, w, h].

    Returns:
        list: List of polygons in COCO format (list of lists of coordinates).
    éÿ   )Ú	mask_utilÚdecoder2   )r3   r   r   s      r   Úconvert_rle_to_polyr8   N   s)   € õ Ô˜CÑ Ô  3Ñ&€DÝ˜t TÑ*Ô*Ð*r	   Úannc                 ó’   — t          | d         ¦  «        t          u r*| d         | d<   t          | d         | d         ¦  «        | d<   | S )a¬  Convert annotation segmentation from RLE to polygon style and save RLE
    in the 'counts' variable.

    Args:
        ann (dict): Annotation dictionary with at least 'segmentation' (RLE) and 'bbox' fields.

    Returns:
        dict: Annotation dictionary with 'segmentation' converted to polygons and original RLE stored in 'counts'.

    Raises:
        Exception: If OpenCV is not available and conversion is required.
    ÚsegmentationÚcountsr   )ÚtypeÚdictr8   )r9   s    r   Úconvert_ann_rle_to_polyr?   \   sL   € õ ˆC�ÔÑ Ô ¥DÐ(Ð(Ø˜NÔ+ˆˆH‰Ý1°#°nÔ2EÀsÈ6Ä{ÑSÔSˆˆNÑØ€Jr	   )r
   )Únumpyr   Úfaster_coco_eval.core.maskÚcorer   r6   r   r   r   r   Úndarrayr!   Úfloatr2   r>   r8   r?   © r	   r   ú<module>rF      s  ðØ Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .ðØ€J€J€JàÐÐøØð ð ð Ø
€CØÐÐÐðøøøð
#ð #ð #ð5ð 5˜bœjð 5°ð 5ÀEð 5ÐTXð 5ð 5ð 5ð 5ðp+˜Tð +¨ð +°$ð +ð +ð +ð +ð ð ¨$ð ð ð ð ð ð s   � –	"¡"