o
    Wh                     @   sD   d dl Z d dlmZ d dlmZ d dlmZmZ G dd deZdS )    N)Results)DetectionPredictor)DEFAULT_CFGopsc                       s0   e Zd ZdZeddf fdd	Zdd Z  ZS )OBBPredictora  
    A class extending the DetectionPredictor class for prediction based on an Oriented Bounding Box (OBB) model.

    This predictor handles oriented bounding box detection tasks, processing images and returning results with rotated
    bounding boxes.

    Attributes:
        args (namespace): Configuration arguments for the predictor.
        model (torch.nn.Module): The loaded YOLO OBB model.

    Examples:
        >>> from ultralytics.utils import ASSETS
        >>> from ultralytics.models.yolo.obb import OBBPredictor
        >>> args = dict(model="yolo11n-obb.pt", source=ASSETS)
        >>> predictor = OBBPredictor(overrides=args)
        >>> predictor.predict_cli()
    Nc                    s   t  ||| d| j_dS )a  
        Initialize OBBPredictor with optional model and data configuration overrides.

        This constructor sets up an OBBPredictor instance for oriented bounding box detection tasks.

        Args:
            cfg (dict, optional): Default configuration for the predictor.
            overrides (dict, optional): Configuration overrides that take precedence over the default config.
            _callbacks (list, optional): List of callback functions to be invoked during prediction.

        Examples:
            >>> from ultralytics.utils import ASSETS
            >>> from ultralytics.models.yolo.obb import OBBPredictor
            >>> args = dict(model="yolo11n-obb.pt", source=ASSETS)
            >>> predictor = OBBPredictor(overrides=args)
        obbN)super__init__argstask)selfcfg	overrides
_callbacks	__class__ W/var/www/vscode/kcb/lib/python3.10/site-packages/ultralytics/models/yolo/obb/predict.pyr	      s   zOBBPredictor.__init__c                 C   s   t tj|ddddf |ddddf gdd}t j|jdd |ddddf |jdd|ddddf< tj||ddddf gdd}t||| jj|d	S )
a  
        Construct the result object from the prediction.

        Args:
            pred (torch.Tensor): The predicted bounding boxes, scores, and rotation angles with shape (N, 6) where
                the last dimension contains [x, y, w, h, confidence, class_id, angle].
            img (torch.Tensor): The image after preprocessing with shape (B, C, H, W).
            orig_img (np.ndarray): The original image before preprocessing.
            img_path (str): The path to the original image.

        Returns:
            (Results): The result object containing the original image, image path, class names, and oriented bounding boxes.
        N   )dim   T)xywh   )pathnamesr   )	r   regularize_rboxestorchcatscale_boxesshaper   modelr   )r   predimgorig_imgimg_pathrboxesr   r   r   r   construct_result1   s   8>"zOBBPredictor.construct_result)__name__
__module____qualname____doc__r   r	   r'   __classcell__r   r   r   r   r   
   s    r   )	r   ultralytics.engine.resultsr   &ultralytics.models.yolo.detect.predictr   ultralytics.utilsr   r   r   r   r   r   r   <module>   s
   