
    |hH                     J    d dl Z d dlmZ d dlmZ d dlmZmZ  G d de      Zy)    N)Results)DetectionPredictor)DEFAULT_CFGopsc                   0     e Zd ZdZeddf fd	Zd Z x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                 J    t         |   |||       d| j                  _        y)a  
        Initialize OBBPredictor with optional model and data configuration overrides.

        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__s       b/var/www/html/test/engine/venv/lib/python3.12/site-packages/ultralytics/models/yolo/obb/predict.pyr   zOBBPredictor.__init__   s!     	i4		    c           	         t        j                  t        j                  |ddddf   |ddddf   gd            }t        j                  |j
                  dd |ddddf   |j
                  d      |ddddf<   t        j                  ||ddddf   gd      }t        ||| j                  j                  |	      S )
a  
        Construct the result object from the prediction.

        Args:
            pred (torch.Tensor): The predicted bounding boxes, scores, and rotation angles with shape (N, 7) 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
   s          r   construct_resultzOBBPredictor.construct_result/   s     &&uyy$q"1"u+tArsF|1LRT'UV		!"va!e}hnn[_`q"1"uiia1f.B7xhdjj6F6FCPPr   )__name__
__module____qualname____doc__r   r   r*   __classcell__)r   s   @r   r   r   
   s    $ '$4 $Qr   r   )	r    ultralytics.engine.resultsr   &ultralytics.models.yolo.detect.predictr   ultralytics.utilsr   r   r    r   r   <module>r4      s"     . E .7Q% 7Qr   