
    h                    v    S SK Jr  S SKJr  S SKJrJr           S                     SS jjrg)    )annotations)Path)SAMYOLONc
                   [        U5      n[        U5      n[        U 5      n U	(       d  U R                  U R                   S3-  n	[        U	5      R                  SSS9  U" U SX4XVXxS9n
U
 GHG  nUR                  R                  R                  5       R                  5       =n(       d  M?  UR                  R                  nU" UR                  USSUS9nUS   R                  R                  n[        [        U	5      [        UR                  5      R                  -   S3S	S
S9 n[!        U5       Hv  u  nnUR#                  5       (       d  M  [%        [&        UR)                  S5      R                  5       5      nUR+                  UU    S3SR-                  U5      -   S-   5        Mx     SSS5        GMJ     g! , (       d  f       GM]  = f)aC  
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="yolo11n.pt", sam_model="mobile_sam.pt")
_auto_annotate_labelsT)exist_okparents)streamdeviceconfiouimgszmax_detclassesF)bboxesverbosesaver   r   z.txtwzutf-8)encoding 
N)r   r   r   parentstemmkdirboxesclsinttolistxyxyorig_imgmasksxynopenpath	enumerateanymapstrreshapewritejoin)data	det_model	sam_modelr   r   r   r   r   r   
output_dirdet_resultsresult	class_idsr   sam_resultssegmentsfissegments                       T/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/data/annotator.pyauto_annotater<   
   s   F YIII:D[[dii[0E#FF
D$7T&SZK ((,,.557797LL%%E#FOOE5W\eklK"1~++//Hj)D,=,B,BBC4H#X_`de%h/DAquuww"%c199R=+?+?+A"B9Q<. 2SXXg5F F MN 0 a`  a`s   #%F7AF77
G	)	z
yolo11x.ptzsam_b.pt g      ?g?i  i,  NN)r.   z
str | Pathr/   r*   r0   r*   r   r*   r   floatr   r>   r   r   r   r   r   zlist[int] | Noner1   zstr | Path | NonereturnNone)
__future__r   pathlibr   ultralyticsr   r   r<        r;   <module>rF      s    #  !
 " $$(9O
9O9O 9O 	9O
 9O 
9O 9O 9O 9O "9O 
9OrE   