§
    l¬¸jù  ã                  óJ   — d dl mZ d dlmZ d dlmZmZ 	 	 	 	 	 	 	 	 	 dd d„ZdS )!é    )Úannotations)ÚPath)ÚSAMÚYOLOú
yolo26x.ptúsam_b.ptÚ ç      Ð?çÍÌÌÌÌÌÜ?é€  é,  NÚdataú
str | PathÚ	det_modelÚstrÚ	sam_modelÚdeviceÚconfÚfloatÚiouÚimgszÚintÚmax_detÚclassesúlist[int] | NoneÚ
output_dirústr | Path | NoneÚreturnÚNonec
           
     ó¬  — t          |¦  «        }t          |¦  «        }t          | ¦  «        } |	s| j        | j        › d�z  }	t          |	¦  «                             dd¬¦  «          || d||||||¬¦  «        }
|
D �]W}|j        j                             ¦   «          	                    ¦   «         x}�r!|j        j
        } ||j        |dd|¬¦  «        }|d         j        j        }t          t          |	¦  «        t          |j        ¦  «        j        z  › d�d	d
¬¦  «        5 }t!          |¦  «        D ]‰\  }}t#          |¦  «        dk    rqt%          t&          |                     d¦  «         	                    ¦   «         ¦  «        }|                     ||         › d�d                     |¦  «        z   dz   ¦  «         ŒŠ	 ddd¦  «         n# 1 swxY w Y   �ŒYdS )aŠ  Automatically annotate images using a YOLO object detection model and a SAM segmentation model.

    This function processes images in a specified directory, detects objects using a YOLO model, and then generates
    segmentation masks using a SAM model. The resulting annotations are saved as text files in YOLO format.

    Args:
        data (str | Path): Path to a folder containing images to be annotated.
        det_model (str): Path or name of the pre-trained YOLO detection model.
        sam_model (str): Path or name of the pre-trained SAM segmentation model.
        device (str): Device to run the models on (e.g., 'cpu', 'cuda', '0'). Empty string for auto-selection.
        conf (float): Confidence threshold for detection model.
        iou (float): IoU threshold for filtering overlapping boxes in detection results.
        imgsz (int): Input image resize dimension.
        max_det (int): Maximum number of detections per image.
        classes (list[int], optional): Filter predictions to specified class IDs, returning only relevant detections.
        output_dir (str | Path, optional): Directory to save the annotated results. If None, creates a default directory
            based on the input data path.

    Examples:
        >>> from ultralytics.data.annotator import auto_annotate
        >>> auto_annotate(data="ultralytics/assets", det_model="yolo26n.pt", sam_model="mobile_sam.pt")
    Ú_auto_annotate_labelsT)Úexist_okÚparents)Ústreamr   r   r   r   r   r   F)ÚbboxesÚverboseÚsaver   r   z.txtÚwzutf-8)Úencodingé   éÿÿÿÿú ú
N)r   r   r   ÚparentÚstemÚmkdirÚboxesÚclsr   ÚtolistÚxyxyÚorig_imgÚmasksÚxynÚopenÚpathÚ	enumerateÚlenÚmapr   ÚreshapeÚwriteÚjoin)r   r   r   r   r   r   r   r   r   r   Údet_resultsÚresultÚ	class_idsr1   Úsam_resultsÚsegmentsÚfÚiÚsÚsegments                       új/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/data/annotator.pyÚauto_annotaterJ   
   s;  € õD �Y‘”€IÝ�I‘”€Iå�‰:Œ:€DØð GØ”[ d¤iÐ#FÐ#FÐ#FÑFˆ
ÝˆÑÔ×Ò D°$ÐÑ7Ô7Ð7à�)Ø�T &¨t¸ÀEÐSZÐdkðñ ô €Kð ð 
Oñ 
OˆØœÔ(×,Ò,Ñ.Ô.×5Ò5Ñ7Ô7Ð7ˆ9ñ 		OØ”LÔ%ˆEØ#˜) F¤O¸EÈ5ÐW\ÐekÐlÑlÔlˆKØ" 1”~Ô+Ô/ˆHå�˜jÑ)Ô)­D°´Ñ,=Ô,=Ô,BÑBÐHÐHÐHÈ#ÐX_Ð`Ñ`Ô`ð OÐdeÝ% hÑ/Ô/ð Oð O‘D�A�qÝ˜1‘v”v ’{�{Ý"%¥c¨1¯9ª9°R©=¬=×+?Ò+?Ñ+AÔ+AÑ"BÔ"B˜ØŸš 9¨Q¤<Ð 2Ð 2Ð 2°S·X²X¸gÑ5FÔ5FÑ FÈÑ MÑNÔNÐNøðOðOð Oð Oñ Oô Oð Oð Oð Oð Oð Oð Oøøøð Oð Oð Oð Oùð
Oð 
Os   Ä BGÇG	ÇG	)	r   r   r	   r
   r   r   r   NN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )Ú
__future__r   Úpathlibr   Úultralyticsr   r   rJ   © ó    rI   ú<module>rP      sŠ   ðð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à !Ð !Ð !Ð !Ð !Ð !Ð !Ð !ð
 "ØØØØØØØ $Ø$(ð8Oð 8Oð 8Oð 8Oð 8Oð 8Oð 8OrO   