
    /jJ
                    ^    d dl mZ 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
dS )    )annotationsN)Results)DetectionPredictor)DEFAULT_CFGopsc                  2     e Zd ZdZeddfd 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="yolo26n-obb.pt", source=ASSETS)
        >>> predictor = OBBPredictor(overrides=args)
        >>> predictor.predict_cli()
    N
_callbacksdict | Nonec                f    t                                          |||           d| j        _        dS )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 (dict, optional): Dictionary of callback functions to be invoked during prediction.
        obbN)super__init__argstask)selfcfg	overridesr
   	__class__s       h/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/models/yolo/obb/predict.pyr   zOBBPredictor.__init__   s.     	i444	    c                b   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   )torchcatr   scale_boxesshaper   modelr    )r   predimgorig_imgimg_pathrboxesr   s          r   construct_resultzOBBPredictor.construct_result)   s     DBQBKaaaf6B???	!""vaaa!e}hn[_```qqq"1"uiaaa1f.B777xhdj6FCPPPPr   )r
   r   )__name__
__module____qualname____doc__r   r   r+   __classcell__)r   s   @r   r	   r	      sl         " '$RV 	 	 	 	 	 	 	Q Q Q Q Q Q Qr   r	   )
__future__r   r!   ultralytics.engine.resultsr   &ultralytics.models.yolo.detect.predictr   ultralytics.utilsr   r   r	    r   r   <module>r6      s    # " " " " "  . . . . . . E E E E E E . . . . . . . ..Q .Q .Q .Q .Q% .Q .Q .Q .Q .Qr   