o
    VhV                     @   s   d dl mZ d dlmZmZmZ d dlmZmZ 								
		ddee	ef de	de	de	de
de
dededeee  deee	ef  ddfddZdS )    )Path)ListOptionalUnion)SAMYOLO
yolo11x.ptsam_b.pt       ??  ,  Ndata	det_model	sam_modeldeviceconfiouimgszmax_detclasses
output_dirreturnc
              
   C   s6  t |}t|}t| } |	s| j| j d }	t|	jddd || d||||||d}
|
D ]j}|jj 	 }|r|jj
}||j|dd|d}|d jj}tt|	t|jj  dd	d
d0}t|D ]#\}}| rtt|d	 }|||  dd| d  qeW d   n1 sw   Y  q.dS )a3  
    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.

    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').
        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] | None): Filter predictions to specified class IDs, returning only relevant detections.
        output_dir (str | Path | None): Directory to save the annotated results. If None, a default directory is created.

    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)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clsinttolistxyxyorig_imgmasksxynopenpath	enumerateanymapstrreshapewritejoin)r   r   r   r   r   r   r   r   r   r   det_resultsresult	class_idsr)   sam_resultssegmentsfissegment rC   N/var/www/vscode/kcb/lib/python3.10/site-packages/ultralytics/data/annotator.pyauto_annotate	   s2   "&"rE   )	r   r	   r
   r   r   r   r   NN)pathlibr   typingr   r   r   ultralyticsr   r   r6   floatr+   rE   rC   rC   rC   rD   <module>   sF   

	
