
    FPhv                        d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlm	Z
 d dlmZmZ d dlmZ d dlmZ d dlmZ d dlmZ dd	lmZmZ  G d
 d      Z G d d      Z G d d      Z G d de      Z G d de      Z G d d      Z G d d      Z G d d      Z  G d d      Z! G d d      Z" G d d      Z# G d  d!      Z$d,d"Z%d-d#Z&d$ Z'	 	 	 	 	 	 	 	 	 	 	 d.d%Z( G d& d'      Z) G d( d)      Z* G d* d+      Z+y)/    N)deepcopy)LOGGERcolorstr)check_version)	Instances)bbox_ioa)segment2box   )polygons2maskspolygons2masks_overlapc                   0    e Zd ZdZddZd Zd Zd Zd Zy)	BaseTransformap  
    Base class for image transformations.

    This is a generic transformation class that can be extended for specific image processing needs.
    The class is designed to be compatible with both classification and semantic segmentation tasks.

    Methods:
        __init__: Initializes the BaseTransform object.
        apply_image: Applies image transformation to labels.
        apply_instances: Applies transformations to object instances in labels.
        apply_semantic: Applies semantic segmentation to an image.
        __call__: Applies all label transformations to an image, instances, and semantic masks.
    Nc                      y)z%Initializes the BaseTransform object.N selfs    cC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\ultralytics/data/augment.py__init__zBaseTransform.__init__%           c                      y)z(Applies image transformations to labels.Nr   r   labelss     r   apply_imagezBaseTransform.apply_image)   r   r   c                      y)z6Applies transformations to object instances in labels.Nr   r   s     r   apply_instanceszBaseTransform.apply_instances-   r   r   c                      y)z*Applies semantic segmentation to an image.Nr   r   s     r   apply_semanticzBaseTransform.apply_semantic1   r   r   c                 j    | j                  |       | j                  |       | j                  |       y)zMApplies all label transformations to an image, instances, and semantic masks.N)r   r   r   r   s     r   __call__zBaseTransform.__call__5   s,     V$F#r   returnN)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r   r      s     $r   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)Composez3Class for composing multiple image transformations.c                     || _         y)z9Initializes the Compose object with a list of transforms.N
transforms)r   r+   s     r   r   zCompose.__init__?   s	    $r   c                 8    | j                   D ]
  } ||      } |S )z2Applies a series of transformations to input data.r*   )r   datats      r   r    zCompose.__call__C   s    AT7D !r   c                 :    | j                   j                  |       y)z;Appends a new transform to the existing list of transforms.N)r+   append)r   	transforms     r   r0   zCompose.appendI   s    y)r   c                     | j                   S )z:Converts the list of transforms to a standard Python list.r*   r   s    r   tolistzCompose.tolistM   s    r   c                     | j                   j                   ddj                  | j                  D cg c]  }|  c}       dS c c}w )z.Returns a string representation of the object.(, ))	__class__r#   joinr+   )r   r.   s     r   __repr__zCompose.__repr__Q   sE    ..))*!DIIt6W!!v6W,X+YYZ[[6Ws   
AN)	r#   r$   r%   r&   r   r    r0   r3   r:   r   r   r   r(   r(   <   s    =%*\r   r(   c                   ,    e Zd ZdZdddZd Zd Zd Zy)	BaseMixTransformze
    Class for base mix (MixUp/Mosaic) transformations.

    This implementation is from mmyolo.
    Nc                 .    || _         || _        || _        y)zUInitializes the BaseMixTransform object with dataset, pre_transform, and probability.Ndatasetpre_transformp)r   r?   r@   rA   s       r   r   zBaseMixTransform.__init__]   s    *r   c                    t        j                  dd      | j                  kD  r|S | j                         }t	        |t
              r|g}|D cg c]  }| j                  j                  |       }}| j                  't        |      D ]  \  }}| j                  |      ||<    ||d<   | j                  |      }|j                  dd       |S c c}w )zMApplies pre-processing transforms and mixup/mosaic transforms to labels data.r   r
   N
mix_labels)randomuniformrA   get_indexes
isinstanceintr?   get_image_and_labelr@   	enumerate_mix_transformpop)r   r   indexesirC   r-   s         r   r    zBaseMixTransform.__call__c   s    >>!Q$&&(M ""$gs#iG DKK7adll66q97
K)$Z04 $ 2 24 8
1 1)| $$V,

<& Ls   "Cc                     t         )z=Applies MixUp or Mosaic augmentation to the label dictionary.NotImplementedErrorr   s     r   rK   zBaseMixTransform._mix_transformz       !!r   c                     t         )z8Gets a list of shuffled indexes for mosaic augmentation.rP   r   s    r   rF   zBaseMixTransform.get_indexes~   rR   r   N        r!   )r#   r$   r%   r&   r   r    rK   rF   r   r   r   r<   r<   V   s    .""r   r<   c                   T     e Zd ZdZd	 fd	Zd
dZd Zd Zd Ze	d        Z
d Z xZS )Mosaicaj  
    Mosaic augmentation.

    This class performs mosaic augmentation by combining multiple (4 or 9) images into a single mosaic image.
    The augmentation is applied to a dataset with a given probability.

    Attributes:
        dataset: The dataset on which the mosaic augmentation is applied.
        imgsz (int, optional): Image size (height and width) after mosaic pipeline of a single image. Default to 640.
        p (float, optional): Probability of applying the mosaic augmentation. Must be in the range 0-1. Default to 1.0.
        n (int, optional): The grid size, either 4 (for 2x2) or 9 (for 3x3).
    c                     d|cxk  rdk  sn J d| d       |dv sJ d       t         |   ||       || _        || _        | dz  | dz  f| _        || _        y	)
zKInitializes the object with a dataset, image size, probability, and border.r         ?z3The probability should be in range [0, 1], but got .)   	   zgrid must be equal to 4 or 9.)r?   rA      N)superr   r?   imgszbordern)r   r?   r_   rA   ra   r8   s        r   r   zMosaic.__init__   sv    A}}X STUSVVWXX}F{;;;{A.
v{UFaK0r   c           	      2   |rAt        j                  t        | j                  j                        | j
                  dz
        S t        | j
                  dz
        D cg c].  }t        j                  dt        | j                        dz
        0 c}S c c}w )z1Return a list of random indexes from the dataset.r
   kr   )	rD   choiceslistr?   bufferra   rangerandintlen)r   rg   _s      r   rF   zMosaic.get_indexes   sn    >>$t||':':";tvvzJJFKDFFUVJFWXFWFNN1c$,,&7!&;<FWXXXs   3Bc                     |j                  dd      J d       t        |j                  dg             sJ d       | j                  dk(  r| j                  |      S | j	                  |      S )z9Apply mixup transformation to the input image and labels.
rect_shapeNz'rect and mosaic are mutually exclusive.rC   z-There are no other images for mosaic augment.r[   )getrj   ra   _mosaic4_mosaic9r   s     r   rK   zMosaic._mix_transform   se    zz,-5`7``56::lB/0a2aa0(,!t}}V$Nv9NNr   c           	      T   g }| j                   fd| j                  D        \  }}t        d      D ]  }|dk(  r|n
|d   |dz
     }|d   }|j                  d      \  }}	|dk(  ryt	        j
                  dz  dz  |j                  d   fd	t        j                  
      }
t        ||	z
  d      t        ||z
  d      ||f\  }}}}|	||z
  z
  |||z
  z
  |	|f\  }}}}n|dk(  rG|t        ||z
  d      t        ||	z   dz        |f\  }}}}d|||z
  z
  t        |	||z
        |f\  }}}}n|dk(  rGt        ||	z
  d      ||t        dz  ||z         f\  }}}}|	||z
  z
  d|	t        ||z
  |      f\  }}}}nU|dk(  rP||t        ||	z   dz        t        dz  ||z         f\  }}}}ddt        |	||z
        t        ||z
  |      f\  }}}}|f   
f<   ||z
  }||z
  }| j                  |||      }|j                  |        | j                  |      }
|d<   |S )zCreate a 2x2 image mosaic.c              3   j   K   | ]*  }t        t        j                  | d z  |z                , yw)r]   N)rH   rD   rE   ).0xss     r   	<genexpr>z"Mosaic._mosaic4.<locals>.<genexpr>   s,     Jk#fnnaRQ34ks   03r[   r   rC   r
   imgresized_shaper]   r   dtype   )r_   r`   rh   rL   npfullshapeuint8maxmin_update_labelsr0   _cat_labels)r   r   mosaic_labelsycxcrN   labels_patchrw   hwimg4x1ay1ax2ay2ax1by1bx2by2bpadwpadhfinal_labelsru   s                         @r   ro   zMosaic._mosaic4   s   JJJdkkJBqA%&!V61Ea!e1LLu%C##O4DAq AvwwAq1uciil;SQ%(a^Sa^R%K"S#s%&#)_a39oq!%K"S#sa%'R!VQR!VQU9KR%O"S#s%&S3YQc	9JA%M"S#sa%(a^RSQQ=O%O"S#s%&#)_aCc	1<M%M"S#sa%'SaQ-?QUBQRFAS%S"S#s%&3q#)+<c#)Q>O%O"S#s%(S#c')9%:DS#c'!"9D9D..|T4HL  .5 6 ''6"Ur   c                    g }| j                   }d\  }}t        d      D ]  }|dk(  r|n
|d   |dz
     }|d   }|j                  d      \  }	}
|dk(  rMt        j                  |dz  |dz  |j
                  d	   fd
t        j                        }|	|
}}||||
z   ||	z   f}n|dk(  r|||	z
  ||
z   |f}n|d	k(  r||z   ||	z
  ||z   |
z   |f}n|dk(  r|z   |||z   |
z   ||	z   f}n|dk(  r|z   ||z   ||z   |
z   ||z   |	z   f}nw|dk(  r|z   |
z
  |z   ||z   ||z   |	z   f}nY|dk(  r|z   |z
  |
z
  |z   ||z   |z
  ||z   |	z   f}n5|dk(  r||
z
  |z   |	z
  |||z   f}n|dk(  r||
z
  |z   |z
  |	z
  |||z   |z
  f}dd	 \  }}d |D        \  }}}}|||z
  d||z
  df   ||||f<   |	|
}}| j                  ||| j                  d   z   || j                  d   z         }|j                  |        | j                  |      }| j                  d    | j                  d   | j                  d    | j                  d   f   |d<   |S )zCreate a 3x3 image mosaic.)r   r\   r   rC   r
   rw   rx   r|   r]   ry   rz   r[               Nc              3   4   K   | ]  }t        |d         yw)r   N)r   rs   rt   s     r   rv   z"Mosaic._mosaic9.<locals>.<genexpr>   s     3Ac!Qis   )r_   rh   rL   r}   r~   r   r   r   r`   r0   r   )r   r   r   ru   hpwprN   r   rw   r   r   img9h0w0cr   r   x1y1x2y2r   s                         r   rp   zMosaic._mosaic9   s   JJBqA%&!V61Ea!e1LLu%C##O4DAq AvwwAq1uciil;SQABq!a%Q&aq1ua!eQ&aFAE1r6A:q0aFAq2vz1q50aFAFAFQJB
:aFQJBBB
:aFRK!OQVQVb[!b&1*DaE1r6A:q!b&0aE1r6B;?Aq2v{:2AJD$33NBB "%R$YZd%;!<DB2B  ..|TDKKPQN=RTX[_[f[fgh[iTijL  .K L ''6"DKKN?4;;q>#ADKKPQN?SWS^S^_`SaCa#abUr   c                     | d   j                   dd \  }}| d   j                  d       | d   j                  ||       | d   j                  ||       | S )Update labels.rw   Nr]   	instancesxyxyformat)r   convert_bboxdenormalizeadd_padding)r   r   r   nhnws        r   r   zMosaic._update_labels   sc     $$Ra(B{(((7{''B/{''d3r   c                    t        |      dk(  ri S g }g }| j                  dz  }|D ]*  }|j                  |d          |j                  |d          , |d   d   |d   d   ||ft        j                  |d      t        j                  |d      | j                  d}|d   j                  ||       |d   j                         }|d   |   |d<   |S )	z3Return labels with mosaic border instances clipped.r   r]   clsr   im_file	ori_shapeaxis)r   r   rx   r   r   mosaic_border)	rj   r_   r0   r}   concatenater   r`   clipremove_zero_area_boxes)r   r   r   r   r_   r   r   goods           r   r   zMosaic._cat_labels  s    }"I	

Q#FJJve}%VK01 $ %Q'	2&q)+6#U^>>#q)"..yqA![[* 	[!&&ue4K(??A*51$7Ur   )  rY   r[   )T)r#   r$   r%   r&   r   rF   rK   ro   rp   staticmethodr   r   __classcell__r8   s   @r   rW   rW      s>    YO"H.`  r   rW   c                   2     e Zd ZdZdd fdZd Zd Z xZS )MixUpz5Class for applying MixUp augmentation to the dataset.c                 *    t         |   |||       y)zXInitializes MixUp object with dataset, pre_transform, and probability of applying MixUp.r>   N)r^   r   )r   r?   r@   rA   r8   s       r   r   zMixUp.__init__  s    Kr   c                 Z    t        j                  dt        | j                        dz
        S )z$Get a random index from the dataset.r   r
   )rD   ri   rj   r?   r   s    r   rF   zMixUp.get_indexes#  s!    ~~aT\\!2Q!677r   c                 D   t         j                  j                  dd      }|d   d   }|d   |z  |d   d|z
  z  z   j                  t         j                        |d<   t        j                  |d   |d   gd      |d<   t        j                  |d   |d   gd      |d<   |S )	zGApplies MixUp augmentation as per https://arxiv.org/pdf/1710.09412.pdf.g      @@rC   r   rw   r
   r   r   r   )r}   rD   betaastyper   r   r   )r   r   rlabels2s       r   rK   zMixUp._mix_transform'  s    IINN4&&q)*WU^q1u-EEMMbhhWu'33VK5H'R]J^4_fgh{uwu~'FJur   rT   r!   )r#   r$   r%   r&   r   rF   rK   r   r   s   @r   r   r     s    ?L8r   r   c                   L    e Zd ZdZ	 	 	 	 	 	 	 d
dZd Zd Zd Zd Zd Z	dd	Z
y)RandomPerspectivea  
    Implements random perspective and affine transformations on images and corresponding bounding boxes, segments, and
    keypoints. These transformations include rotation, translation, scaling, and shearing. The class also offers the
    option to apply these transformations conditionally with a specified probability.

    Attributes:
        degrees (float): Degree range for random rotations.
        translate (float): Fraction of total width and height for random translation.
        scale (float): Scaling factor interval, e.g., a scale factor of 0.1 allows a resize between 90%-110%.
        shear (float): Shear intensity (angle in degrees).
        perspective (float): Perspective distortion factor.
        border (tuple): Tuple specifying mosaic border.
        pre_transform (callable): A function/transform to apply to the image before starting the random transformation.

    Methods:
        affine_transform(img, border): Applies a series of affine transformations to the image.
        apply_bboxes(bboxes, M): Transforms bounding boxes using the calculated affine matrix.
        apply_segments(segments, M): Transforms segments and generates new bounding boxes.
        apply_keypoints(keypoints, M): Transforms keypoints.
        __call__(labels): Main method to apply transformations to both images and their corresponding annotations.
        box_candidates(box1, box2): Filters out bounding boxes that don't meet certain criteria post-transformation.
    Nc                 f    || _         || _        || _        || _        || _        || _        || _        y)zDInitializes RandomPerspective object with transformation parameters.N)degrees	translatescaleshearperspectiver`   r@   )r   r   r   r   r   r   r`   r@   s           r   r   zRandomPerspective.__init__I  s7     "

&*r   c                    t        j                  dt         j                        }|j                  d    dz  |d<   |j                  d    dz  |d<   t        j                  dt         j                        }t	        j
                  | j                   | j                        |d<   t	        j
                  | j                   | j                        |d	<   t        j                  dt         j                        }t	        j
                  | j                   | j                        }t	        j
                  d| j                  z
  d| j                  z         }t        j                  |d
|      |dd t        j                  dt         j                        }t        j                  t	        j
                  | j                   | j                        t        j                  z  dz        |d<   t        j                  t	        j
                  | j                   | j                        t        j                  z  dz        |d<   t        j                  dt         j                        }	t	        j
                  d| j                  z
  d| j                  z         | j                   d   z  |	d<   t	        j
                  d| j                  z
  d| j                  z         | j                   d   z  |	d<   |	|z  |z  |z  |z  }
|d   dk7  s.|d   dk7  s&|
t        j                  d      k7  j#                         rV| j                  r$t        j$                  ||
| j                   d      }n&t        j&                  ||
dd | j                   d      }||
|fS )a[  
        Applies a sequence of affine transformations centered around the image center.

        Args:
            img (ndarray): Input image.
            border (tuple): Border dimensions.

        Returns:
            img (ndarray): Transformed image.
            M (ndarray): Transformation matrix.
            s (float): Scale factor.
        r|   rz   r
   r]   )r   r]   r   )r
   r]   )r]   r   )r]   r
   r   r   )anglecenterr   N   )r   r
   )r
   r         ?ry   ry   ry   )dsizeborderValue)r}   eyefloat32r   rD   rE   r   r   r   cv2getRotationMatrix2Dmathtanr   pir   sizeanywarpPerspective
warpAffine)r   rw   r`   CPRaru   STMs              r   affine_transformz"RandomPerspective.affine_transform[  s    FF1BJJ'99Q<-!#$99Q<-!#$ FF1BJJ'..$"2"2!2D4D4DE$..$"2"2!2D4D4DE$ FF1BJJ'NNDLL=$,,7NN1tzz>1tzz>:''aaH"1 FF1BJJ'((6>>4::+tzzBTWWLsRS$((6>>4::+tzzBTWWLsRS$ FF1BJJ'..t~~!5sT^^7KLtyyYZ|[$..t~~!5sT^^7KLtyyYZ|[$ EAIMA1INq	QAN3G3G3I))#q		_nnS!BQ%tyyo^Aqyr   c                 |   t        |      }|dk(  r|S t        j                  |dz  df|j                        }|ddg df   j	                  |dz  d      |ddddf<   ||j
                  z  }| j                  r|ddddf   |ddddf   z  n
|ddddf   j	                  |d      }|ddg d	f   }|ddg d
f   }t        j                  |j                  d      |j                  d      |j                  d      |j                  d      f|j                        j	                  d|      j
                  S )a  
        Apply affine to bboxes only.

        Args:
            bboxes (ndarray): list of bboxes, xyxy format, with shape (num_bboxes, 4).
            M (ndarray): affine matrix.

        Returns:
            new_bboxes (ndarray): bboxes after affine, [num_bboxes, 4].
        r   r[   r|   rz   N)r   r
   r]   r|   r   r|   r]   r
   r]   r   )r   r]   r[   r   )r
   r|   r   r   r
   )
rj   r}   onesr{   reshaper   r   r   r   r   )r   bboxesr   ra   xyrt   ys          r   apply_bboxeszRandomPerspective.apply_bboxes  s'    K6MWWa!eQZv||41667??AqI1bqb5	!##X(,(8(8bBQBi"Q!V*$bBQBiPPQRTUV q,q,~~quuQxq1558QUU1XFfll[ccdeghikkkr   c                    |j                   dd \  }}|dk(  rg |fS t        j                  ||z  df|j                        }|j	                  dd      }||ddddf<   ||j
                  z  }|ddddf   |ddddf   z  }|j	                  |dd      }t        j                  |D cg c])  }t        || j                  d   | j                  d         + c}d      }||fS c c}w )a|  
        Apply affine to segments and generate new bboxes from segments.

        Args:
            segments (ndarray): list of segments, [num_samples, 500, 2].
            M (ndarray): affine matrix.

        Returns:
            new_segments (ndarray): list of segments after affine, [num_samples, 500, 2].
            new_bboxes (ndarray): bboxes after affine, [N, 4].
        Nr]   r   r|   rz   r   r
   )	r   r}   r   r{   r   r   stackr	   r   )r   segmentsr   ra   numr   r   s          r   apply_segmentsz RandomPerspective.apply_segments  s     #36x<WWa#gq\8##B*1bqb5	!##X2A2YAqsF#::aQ'QYZQY2;r499Q<1FQYZ\]^x [s   +.C%c                 >   |j                   dd \  }}|dk(  r|S t        j                  ||z  df|j                        }|d   j	                  ||z  d      }|dddf   j	                  ||z  d      |ddddf<   ||j
                  z  }|ddddf   |ddddf   z  }|dddf   dk  |dddf   dk  z  |dddf   | j                  d   kD  z  |dddf   | j                  d   kD  z  }d||<   t        j                  ||gd	
      j	                  ||d      S )z
        Apply affine to keypoints.

        Args:
            keypoints (ndarray): keypoints, [N, 17, 3].
            M (ndarray): affine matrix.

        Returns:
            new_keypoints (ndarray): keypoints after affine, [N, 17, 3].
        Nr]   r   r|   rz   ).r]   r
   .r   r   )r   r}   r   r{   r   r   r   r   )r   	keypointsr   ra   nkptr   visibleout_masks           r   apply_keypointsz!RandomPerspective.apply_keypoints  sH    //"1%46WWa$h])//:F#++AHa8c2A2g&..q4x;1bqb5	!##X2A2YAqsF#q!tHqLR1X\2bAh16MNRTUVXYUYRZ]a]f]fgh]iRij~~r7m"5==aqIIr   c                    | j                   rd|vr| j                  |      }|j                  dd       |d   }|d   }|j                  d      }|j                  d        |j                  |j                  dd	 ddd
     |j                  d| j
                        }|j                  d   |d   d	z  z   |j                  d   |d   d	z  z   f| _        | j                  ||      \  }}}| j                  |j                  |      }|j                  }	|j                  }
t        |	      r| j                  |	|      \  }}	|
| j                  |
|      }
t        ||	|
dd      } |j                   | j                    |j#                  ||d       | j%                  |j                  j&                  |j                  j&                  t        |	      rdnd      }||   |d<   ||   |d<   ||d<   |j                  dd	 |d<   |S )z
        Affine images and targets.

        Args:
            labels (dict): a dict of `bboxes`, `segments`, `keypoints`.
        r   	ratio_padNrw   r   r   r   r   r]   r   r
   r   F)bbox_format
normalizedT)scale_wscale_h	bbox_only{Gz?皙?)box1box2area_thrrx   )r@   rL   r   r   r   r`   r   r   r   r   r   r   rj   r   r  r   r   r   box_candidatesr   )r   r   rw   r   r   r`   r   r   r   r   r   new_instancesrN   s                r   r    zRandomPerspective.__call__  s    /"?''/F

;%UmUmJJ{+	f-	syy!}TrT23OT[[9IIaL6!9q=0#))A,Q2NN	 --c6:Q""9#3#3Q7%%''	x=#228Q?FH ,,Y:I!&(I6^cdDII& 	uEY%5%5%7%7%2%9%9%;%;14XD   J ,A.{Auu"%))BQ-r   c                     |d   |d   z
  |d   |d   z
  }}|d   |d   z
  |d   |d   z
  }
}	t        j                  |	|
|z   z  |
|	|z   z        }|	|kD  |
|kD  z  |	|
z  ||z  |z   z  |kD  z  ||k  z  S )a  
        Compute box candidates based on a set of thresholds. This method compares the characteristics of the boxes
        before and after augmentation to decide whether a box is a candidate for further processing.

        Args:
            box1 (numpy.ndarray): The 4,n bounding box before augmentation, represented as [x1, y1, x2, y2].
            box2 (numpy.ndarray): The 4,n bounding box after augmentation, represented as [x1, y1, x2, y2].
            wh_thr (float, optional): The width and height threshold in pixels. Default is 2.
            ar_thr (float, optional): The aspect ratio threshold. Default is 100.
            area_thr (float, optional): The area ratio threshold. Default is 0.1.
            eps (float, optional): A small epsilon value to prevent division by zero. Default is 1e-16.

        Returns:
            (numpy.ndarray): A boolean array indicating which boxes are candidates based on the given thresholds.
        r]   r   r|   r
   )r}   maximum)r   r  r  wh_thrar_thrr  epsw1h1w2h2ars               r   r  z RandomPerspective.box_candidates  s      a47"DGd1g$5Ba47"DGd1g$5BZZb3hrCx9VV,R27S=0IH0TUY[^dYdeer   )rU   r
  r   rU   rU   r   N)r]   d   r
  gؗҜ<)r#   r$   r%   r&   r   r   r   r   r  r    r  r   r   r   r   r   1  sF    0  #+$3jl2 2J.0dfr   r   c                        e Zd ZdZdddZd Zy)	RandomHSVz
    This class is responsible for performing random adjustments to the Hue, Saturation, and Value (HSV) channels of an
    image.

    The adjustments are random but within limits set by hgain, sgain, and vgain.
    Nc                 .    || _         || _        || _        y)aU  
        Initialize RandomHSV class with gains for each HSV channel.

        Args:
            hgain (float, optional): Maximum variation for hue. Default is 0.5.
            sgain (float, optional): Maximum variation for saturation. Default is 0.5.
            vgain (float, optional): Maximum variation for value. Default is 0.5.
        Nhgainsgainvgain)r   r  r   r!  s       r   r   zRandomHSV.__init__)  s     


r   c                    |d   }| j                   s| j                  s| j                  rt        j                  j                  ddd      | j                   | j                  | j                  gz  dz   }t        j                  t        j                  |t        j                              \  }}}|j                  }t        j                  dd|j                        }||d   z  dz  j                  |      }	t        j                  ||d   z  dd	      j                  |      }
t        j                  ||d
   z  dd	      j                  |      }t        j                  t        j                  ||	      t        j                  ||
      t        j                  ||      f      }t        j                  |t        j                   |       |S )z
        Applies random HSV augmentation to an image within the predefined limits.

        The modified image replaces the original image in the input 'labels' dict.
        rw   r   r
   r|   r      rz   r      r]   )dst)r  r   r!  r}   rD   rE   r   splitcvtColorCOLOR_BGR2HSVr{   aranger   r   mergeLUTCOLOR_HSV2BGR)r   r   rw   r   huesatvalr{   rt   lut_huelut_satlut_valim_hsvs                r   r    zRandomHSV.__call__6  sT    Um::tzz		!!"a+tzz4::tzz.RRUVVAIIcll38I8I&JKMCcIIE		!S0AAaDC'//6Ggga!A$h3/66u=Ggga!A$h3/66u=GYYW 5swwsG7LcggVY[bNcdeFLL!2!2<r   )r   r   r   r!   r#   r$   r%   r&   r   r    r   r   r   r  r  !  s    r   r  c                        e Zd ZdZdddZd Zy)
RandomFlipz
    Applies a random horizontal or vertical flip to an image with a given probability.

    Also updates any instances (bounding boxes, keypoints, etc.) accordingly.
    Nc                 j    |dv s
J d|        d|cxk  rdk  sJ  J || _         || _        || _        y)a  
        Initializes the RandomFlip class with probability and direction.

        Args:
            p (float, optional): The probability of applying the flip. Must be between 0 and 1. Default is 0.5.
            direction (str, optional): The direction to apply the flip. Must be 'horizontal' or 'vertical'.
                Default is 'horizontal'.
            flip_idx (array-like, optional): Index mapping for flipping keypoints, if any.
        )
horizontalverticalz2Support direction `horizontal` or `vertical`, got r   rY   N)rA   	directionflip_idx)r   rA   r:  r;  s       r   r   zRandomFlip.__init__S  sL     66x:lmvlw8xx6A}}}}" r   c                    |d   }|j                  d      }|j                  d       |j                  dd \  }}|j                  rdn|}|j                  rdn|}| j                  dk(  rGt        j
                         | j                  k  r&t        j                  |      }|j                  |       | j                  d	k(  rt        j
                         | j                  k  rvt        j                  |      }|j                  |       | j                  D|j                  8t        j                  |j                  dd| j                  ddf         |_        t        j                  |      |d<   ||d<   |S )
a  
        Applies random flip to an image and updates any instances like bounding boxes or keypoints accordingly.

        Args:
            labels (dict): A dictionary containing the keys 'img' and 'instances'. 'img' is the image to be flipped.
                           'instances' is an object containing bounding boxes and optionally keypoints.

        Returns:
            (dict): The same dict with the flipped image and updated instances under the 'img' and 'instances' keys.
        rw   r   xywhr   Nr]   r
   r9  r8  )rL   r   r   r  r:  rD   rA   r}   flipudfliplrr;  r   ascontiguousarray)r   r   rw   r   r   r   s         r   r    zRandomFlip.__call__d  s4    UmJJ{+	f-yy!}1%%A1%%A1 >>Z'FMMOdff,D))C.CQ>>\)fmmo.F))C.CQ}}(Y-@-@-L&(&:&:9;N;NqRVR_R_abOb;c&d	#,,S1u'{r   )r   r8  Nr!   r4  r   r   r   r6  r6  L  s    !"r   r6  c                   &    e Zd ZdZddZddZd Zy)	LetterBoxzDResize image and padding for detection, instance segmentation, pose.c                 X    || _         || _        || _        || _        || _        || _        y)z5Initialize LetterBox object with specific parameters.N)	new_shapeauto	scaleFillscaleupstrider   )r   rD  rE  rF  rG  r   rH  s          r   r   zLetterBox.__init__  s,    "	"r   Nc           	         |i }||j                  d      n|}|j                  dd }|j                  d| j                        }t	        |t
              r||f}t        |d   |d   z  |d   |d   z        }| j                  st        |d      }||f}t        t        |d   |z              t        t        |d   |z              f}|d   |d   z
  |d   |d   z
  }
}	| j                  rAt        j                  |	| j                        t        j                  |
| j                        }
}	n1| j                  r%d\  }	}
|d   |d   f}|d   |d   z  |d   |d   z  f}| j                  r
|	dz  }	|
dz  }
|ddd	   |k7  r&t        j                   ||t        j"                  
      }| j                  rt        t        |
dz
              ndt        t        |
dz               }}| j                  rt        t        |	dz
              ndt        t        |	dz               }}t        j$                  |||||t        j&                  d      }|j                  d      r|d   ||ff|d<   t)        |      r | j+                  |||	|
      }||d<   ||d<   |S |S )z2Return updated labels and image with added border.Nrw   r]   rm   r   r
   rY   )rU   rU   r   interpolationr
  r   )valuer  rx   )rn   r   rL   rD  rG   rH   r   rG  roundrE  r}   modrH  rF  r   r   resizeINTER_LINEARcopyMakeBorderBORDER_CONSTANTrj   r   )r   r   imagerw   r   rD  r   ratio	new_unpaddwdhtopbottomleftrights                  r   r    zLetterBox.__call__  s}   >F#(=fjje		"1JJ|T^^<	i%"I.I 	!uQx'1a)@A||AsA 1eAhl+,c%a12E.FF	1	!,ilYq\.IB99VVB,bffR.EB^^FB"1y|4IaL58+Yq\E!H-DDE;;!GB!GB2;)#**S)3;K;KLC.2kkc%S/*q#eBQTHoBVV.2kkc%S/*q#eBQTHoBVe  c64@S@S'68::k"#)+#6s"DF;v;((B?FF5M&/F?#MJr   c                     |d   j                  d        |d   j                  |d   j                  dd ddd      |d   j                  |  |d   j	                  ||       |S )r   r   r   r   rw   Nr]   r   )r   r   r   r   r   )r   r   rT  r   r   s        r   r   zLetterBox._update_labels  sv    {(((7'{'')<)<Ra)@2)FG!{!!5){''d3r   )r   r   FFTT    )NN)r#   r$   r%   r&   r   r    r   r   r   r   rB  rB    s    N-^r   rB  c                        e Zd ZdZdddZd Zy)	CopyPastez
    Implements the Copy-Paste augmentation as described in the paper https://arxiv.org/abs/2012.07177. This class is
    responsible for applying the Copy-Paste augmentation on images and their corresponding instances.
    Nc                     || _         y)z
        Initializes the CopyPaste class with a given probability.

        Args:
            p (float, optional): The probability of applying the Copy-Paste augmentation. Must be between 0 and 1.
                                 Default is 0.5.
        NrA   )r   rA   s     r   r   zCopyPaste.__init__  s     r   c                    |d   }|d   }|j                   dd \  }}|j                  d      }|j                  d       |j                  ||       | j                  rt        |j                        rt        |      }|j                   \  }}}t        j                  |j                   t        j                        }	t        |      }
|
j                  |       t        |
j                  |j                        }t        j                  |dk  j                  d	            d
   }t        |      }t!        j"                  t%        |      t'        | j                  |z              D ]  }t        j(                  |||g   fd
      }t+        j(                  ||
|g   fd
      }t-        j.                  |	|j                  |g   j1                  t        j2                        ddt,        j4                          t-        j6                  |d	      }t-        j6                  |	d	      j1                  t8              }||   ||<   ||d<   ||d<   ||d<   |S )a  
        Applies the Copy-Paste augmentation to the given image and instances.

        Args:
            labels (dict): A dictionary containing:
                           - 'img': The image to augment.
                           - 'cls': Class labels associated with the instances.
                           - 'instances': Object containing bounding boxes, and optionally, keypoints and segments.

        Returns:
            (dict): Dict with augmented image and updated instances under the 'img', 'cls', and 'instances' keys.

        Notes:
            1. Instances are expected to have 'segments' as one of their attributes for this augmentation to work.
            2. This method modifies the input dictionary 'labels' in place.
        rw   r   Nr]   r   r   r   g333333?r
   r   rc   r   r   )r
   r
   r
   )r   rL   r   r   rA   rj   r   r}   zerosr   r   r?  r   r   nonzeroallrD   samplerf   rM  r   r   r   drawContoursr   int32FILLEDflipbool)r   r   imr   r   r   r   ra   rk   im_newins_flipioarM   jresultrN   s                   r   r    zCopyPaste.__call__  s   " E]Umxx|1JJ{+	f-a#66c),,-IAhhGAq!XXbhh1F  	*HOOA8??I,<,<=Cjj#*!1!1!!45a8GGA]]4=E$&&1*4EFnnc3s8_1=%119hsm2LSTU	  ););QC)@)G)G)QSUW`beblblm G
 XXb!_F#**40A1IBqEuu'{r   )r   r!   r4  r   r   r   r`  r`    s    
/r   r`  c                       e Zd ZdZddZd Zy)Albumentationsa%  
    Albumentations transformations.

    Optional, uninstall package to disable. Applies Blur, Median Blur, convert to grayscale, Contrast Limited Adaptive
    Histogram Equalization, random change of brightness and contrast, RandomGamma and lowering of image quality by
    compression.
    c           
         || _         d| _        t        d      }	 ddl}t	        |j
                  dd       |j                  d      |j                  d      |j                  d      |j                  d      |j                  d	      |j                  d	      |j                  d
d	      g}|j                  ||j                  ddg            | _        t        j                   |dj#                  d |D              z          y# t$        $ r Y yt&        $ r#}t        j                   | |        Y d}~yd}~ww xY w)z?Initialize the transform object for YOLO bbox formatted params.Nalbumentations: r   1.0.3Thardr	  rb  rU   K   )quality_lowerrA   yoloclass_labels)r   label_fields)bbox_paramsr6   c              3   \   K   | ]$  }|j                   s| j                  d d       & ywzalways_apply=False,  NrA   replacer   s     r   rv   z*Albumentations.__init__.<locals>.<genexpr>(  s,     *h_`Z[dedgdgaS>>:PRT+U_`   ,,)rA   r1   r   albumentationsr   __version__Blur
MedianBlurToGrayCLAHERandomBrightnessContrastRandomGammaImageCompressionr(   
BboxParamsr   infor9   ImportError	Exception)r   rA   prefixAr   es         r   r   zAlbumentations.__init__  s   ,-	(&!--t< t$4 $**S*1$""s";=A YYqall&`n_ol6pYqDNKK*h_`*h!hhi 	 	(KK6(1#''	(s   C.D
 
	E E D;;E c                 $   |d   }|d   }t        |      r|d   j                  d        |d   j                  |j                  dd ddd     |d   j                  }| j
                  rt        j                         | j                  k  rp| j                  |||      }t        |d	         d
kD  rK|d   |d<   t        j                  |d	         |d<   t        j                  |d   t        j                        }|d   j                  |       |S )zLGenerates object detections and returns a dictionary with detection results.rw   r   r   r=  Nr]   r   )rS  r   r}  r}  r   rS  r   rz   )r   )rj   r   	normalizer   r   r1   rD   rA   r}   arrayr   update)r   r   rm  r   r   news         r   r    zAlbumentations.__call__.  s    E]Ums8;,,V4)F;))288BQ<"+=>K(//F~~&--/DFF":nn2f3nOs>*+a/$'LF5M$&HHS-@$AF5MXXc(m2::FF;&&f&5r   N)rY   r4  r   r   r   rt  rt    s    (4r   rt  c                   8    e Zd ZdZ	 	 	 	 	 	 	 ddZd Zd Zd Zy)Formata  
    Formats image annotations for object detection, instance segmentation, and pose estimation tasks. The class
    standardizes the image and instance annotations to be used by the `collate_fn` in PyTorch DataLoader.

    Attributes:
        bbox_format (str): Format for bounding boxes. Default is 'xywh'.
        normalize (bool): Whether to normalize bounding boxes. Default is True.
        return_mask (bool): Return instance masks for segmentation. Default is False.
        return_keypoint (bool): Return keypoints for pose estimation. Default is False.
        mask_ratio (int): Downsample ratio for masks. Default is 4.
        mask_overlap (bool): Whether to overlap masks. Default is True.
        batch_idx (bool): Keep batch indexes. Default is True.
    c                 f    || _         || _        || _        || _        || _        || _        || _        y)z3Initializes the Format class with given parameters.N)r  r  return_maskreturn_keypoint
mask_ratiomask_overlap	batch_idx)r   r  r  r  r  r  r  r  s           r   r   zFormat.__init__Q  s9     '"&.$("r   c                    |j                  d      }|j                  dd \  }}|j                  d      }|j                  d      }|j                  | j                         |j	                  ||       t        |      }| j                  r|r.| j                  ||||      \  }}}t        j                  |      }nYt        j                  | j                  rdn||j                  d   | j                  z  |j                  d   | j                  z        }||d	<   | j                  r|j                  ||       | j                  |      |d<   |rt        j                  |      nt        j                  |      |d<   |rt        j                  |j                        nt        j                  |d
f      |d<   | j                   r"t        j                  |j"                        |d<   | j$                  rt        j                  |      |d<   |S )zWReturn formatted image, classes, bounding boxes & keypoints to be used by 'collate_fn'.rw   Nr]   r   r   r   r
   r   masksr[   r   r   r  )rL   r   r   r  r   rj   r  _format_segmentstorch
from_numpyrd  r  r  r  _format_imgr   r  r   r  )	r   r   rw   r   r   r   r   nlr  s	            r   r    zFormat.__call__b  s   jjyy!}1jjJJ{+	d&6&67a#^(,(=(=iaQR(S%y#((/):):ACIIaLTXTcTcDc$'IIaLDOO$CE#F7O>>1%((-u13((-RuAC5++I,<,<=VXZ[U\I]x"'"2"293F3F"GF;>>"'++b/F;r   c                     t        |j                        dk  rt        j                  |d      }t        j                  |j                  ddd      ddd         }t        j                  |      }|S )z=Format the image for YOLO from Numpy array to PyTorch tensor.r|   r   r]   r   r
   N)rj   r   r}   expand_dimsr@  	transposer  r  )r   rw   s     r   r  zFormat._format_img  s]    syy>A..b)C""3==Aq#9$B$#?@s#
r   c                     |j                   }| j                  r-t        ||f|| j                        \  }}|d   }||   }||   }nt	        ||f|d| j                        }|||fS )z!Convert polygon points to bitmap.)downsample_ratioNr
   )colorr  )r   r  r   r  r   )r   r   r   r   r   r   r  
sorted_idxs           r   r  zFormat._format_segments  su    %% 61vxZ^ZiZi jE:$KE!*-Ij/C"Aq681t_Ei$$r   N)r=  TFFr[   TT)r#   r$   r%   r&   r   r    r  r  r   r   r   r  r  B  s2     $"!&"#"<%r   r  c                 j   t        t        | ||j                        t        |j                        t        |j                  |j                  |j                  |j                  |j                  |rdnt        ||f            g      }| j                  j                  dg       }| j                  r}| j                  j                  dd      }t        |      dk(  r,|j                   d	kD  rd	|_        t#        j$                  d
       n'|r%t        |      |d   k7  rt'        d| d|d          t        |t)        | ||j*                        t-        d      t/        |j0                  |j2                  |j4                        t7        d|j8                        t7        d|j                   |      g      S )z6Convert images to a size suitable for YOLOv8 training.)r_   rA   rb  N)rD  )r   r   r   r   r   r@   r;  	kpt_shaper   rU   uZ   WARNING ⚠️ No 'flip_idx' array defined in data.yaml, setting augmentation 'fliplr=0.0'zdata.yaml flip_idx=z& length must be equal to kpt_shape[0]=)r@   rA   rY   r  r9  )r:  rA   r8  )r:  rA   r;  )r(   rW   mosaicr`  
copy_paster   r   r   r   r   r   rB  r-   rn   use_keypointsrj   r?  r   warning
ValueErrorr   mixuprt  r  hsv_hhsv_shsv_vr6  r>  )r?   r_   hypstretchr@   r;  r  s          r   v8_transformsr    sd   weszz2CNN#KKmm))))")$yE5>/R	

 
M ||
B/HLL$$[$7	x=A#**s"2CJNNwx3x=IaL828*<bclmncobpqrrg]cii@		#))DZ3::6\SZZ(KM N Nr   c                 ,   t        | t              st        d|  d      |rt        | d      n
t	        |       t               g}t        |      st        |      r'|j                  t        j                  ||d             t        j                  |      S )z4Transforms to apply if albumentations not installed.zclassify_transforms() size z# must be integer, not (list, tuple)T)rE  )inplace)rG   rH   	TypeErrorClassifyLetterBox
CenterCropToTensorr   r0   r   	Normalizer(   )r   rectmeanstdr+   s        r   classify_transformsr    sx    dC 5dV;^_``8<#Dt4*TBRT\T^_J
4yCH!++dC>?99Z  r   c                     |||| fS )zgMap HSV (hue, saturation, value) jitter into ColorJitter values (brightness, contrast, saturation, hue)r   )r   ru   vs      r   hsv2colorjitterr    s    aA:r   c                    t        d      }	 ddl}ddlm} t	        |j
                  dd       | r|j                  |||      g}|
rt        j                  | d	       n|dkD  r||j                  |
      gz  }|dkD  r||j                  |
      gz  }t        |||f      rD| |j                  t        |||       gz  }n%|j                  |      |j                  ||      g}||j!                  ||	       |       gz  }t        j                  |dj#                  d |D              z          |j%                  |      S # t&        $ r Y yt(        $ r#}t        j                  | |        Y d}~yd}~ww xY w)zSYOLOv8 classification Albumentations (optional, only used if package is installed).rv  r   N)
ToTensorV2rw  Trx  )heightwidthr   z.auto augmentations are currently not supportedrb  )max_size)r  r  )r  r  r6   c              3   \   K   | ]$  }|j                   s| j                  d d       & ywr  r  r   s     r   rv   z*classify_albumentations.<locals>.<genexpr>  s+     &d[\VW`a`c`c!~~6Lb'Q[\r  )r   r  albumentations.pytorchr  r   r  RandomResizedCropr   r  HorizontalFlipVerticalFlipr   ColorJitterr  SmallestMaxSizer  r  r9   r(   r  r  )augmentr   r   hflipvflipr  r  r  r  r  auto_augr  r  r  r   r  s                   r   classify_albumentationsr    st    ()F$"5ammW48$$DE$JKAvh&TUV19!**U*344A19!..5.122Aue,--!--u)MNOOA""D"11<<tSW<3XYA	akktk-z|<<FTYY&d[\&dddeyy|  $vhqcN##$s   D7E 	E;E;E66E;c                   *     e Zd ZdZd fd	Zd Z xZS )r  a  
    YOLOv8 LetterBox class for image preprocessing, designed to be part of a transformation pipeline, e.g.,
    T.Compose([LetterBox(size), ToTensor()]).

    Attributes:
        h (int): Target height of the image.
        w (int): Target width of the image.
        auto (bool): If True, automatically solves for short side using stride.
        stride (int): The stride value, used when 'auto' is True.
    c                     t         |           t        |t              r||fn|\  | _        | _        || _        || _        y)a}  
        Initializes the ClassifyLetterBox class with a target size, auto-flag, and stride.

        Args:
            size (Union[int, Tuple[int, int]]): The target dimensions (height, width) for the letterbox.
            auto (bool): If True, automatically calculates the short side based on stride.
            stride (int): The stride value, used when 'auto' is True.
        N)r^   r   rG   rH   r   r   rE  rH  )r   r   rE  rH  r8   s       r   r   zClassifyLetterBox.__init__  s:     	)3D#)>$D	r   c                      |j                   dd \  }}t         j                  |z   j                  |z        }t	        ||z        t	        ||z        }} j
                  r fd||fD        n j                   j                  f\  }}t	        ||z
  dz  dz
        t	        ||z
  dz  dz
        }
}	t        j                  ||dfd|j                        }t        j                  |||ft        j                        ||	|	|z   |
|
|z   f<   |S )	a	  
        Resizes the image and pads it with a letterbox method.

        Args:
            im (numpy.ndarray): The input image as a numpy array of shape HWC.

        Returns:
            (numpy.ndarray): The letterboxed and resized image as a numpy array.
        Nr]   c              3   |   K   | ]3  }t        j                  |j                  z        j                  z   5 y w)N)r   ceilrH  )rs   rt   r   s     r   rv   z-ClassifyLetterBox.__call__.<locals>.<genexpr>  s,     KFq$))AO,t{{:Fs   9<r
  r|   ry   rz   rJ  )r   r   r   r   rM  rE  r}   r~   r{   r   rO  rP  )r   rm  imhimwr   r   r   hswsrX  rZ  im_outs   `           r   r    zClassifyLetterBox.__call__  s    88BQ<Sdffsl+S1W~uS1W~1 PTyyKQFK_c_e_egkgmgm^nB26Q,,-ub1f\C5G/HT "b!c:-0ZZQFRURbRb-cs37{DM)*r   )r]  Fr^  r#   r$   r%   r&   r   r    r   r   s   @r   r  r    s    	r   r  c                   *     e Zd ZdZd fd	Zd Z xZS )r  zYOLOv8 CenterCrop class for image preprocessing, designed to be part of a transformation pipeline, e.g.,
    T.Compose([CenterCrop(size), ToTensor()]).
    c                 h    t         |           t        |t              r||fn|\  | _        | _        y)z5Converts an image from numpy array to PyTorch tensor.N)r^   r   rG   rH   r   r   )r   r   r8   s     r   r   zCenterCrop.__init__(  s*    )3D#)>$Dr   c                     |j                   dd \  }}t        ||      }||z
  dz  ||z
  dz  }}t        j                  ||||z   |||z   f   | j                  | j
                  ft        j                        S )a  
        Resizes and crops the center of the image using a letterbox method.

        Args:
            im (numpy.ndarray): The input image as a numpy array of shape HWC.

        Returns:
            (numpy.ndarray): The center-cropped and resized image as a numpy array.
        Nr]   rJ  )r   r   r   rO  r   r   rP  )r   rm  r  r  mrX  rZ  s          r   r    zCenterCrop.__call__-  s|     88BQ<SSM1WNS1WNTzz"Sq[$tax-78466466:JZ]ZjZjkkr   )r   r  r   s   @r   r  r  #  s    I
lr   r  c                   *     e Zd ZdZd fd	Zd Z xZS )r  z^YOLOv8 ToTensor class for image preprocessing, i.e., T.Compose([LetterBox(size), ToTensor()]).c                 0    t         |           || _        y)zGInitialize YOLOv8 ToTensor object with optional half-precision support.N)r^   r   half)r   r  r8   s     r   r   zToTensor.__init__@  s    	r   c                     t        j                  |j                  d      ddd         }t        j                  |      }| j
                  r|j                         n|j                         }|dz  }|S )au  
        Transforms an image from a numpy array to a PyTorch tensor, applying optional half-precision and normalization.

        Args:
            im (numpy.ndarray): Input image as a numpy array with shape (H, W, C) in BGR order.

        Returns:
            (torch.Tensor): The transformed image as a PyTorch tensor in float32 or float16, normalized to [0, 1].
        )r]   r   r
   Nr   g     o@)r}   r@  r  r  r  r  float)r   rm  s     r   r    zToTensor.__call__E  s]     !!",,y"9$B$"?@b!))RWWY
e	r   Fr  r   s   @r   r  r  =  s    h
r   r  r  )   FrU   rU   rU   rY   rY   rY   )Tr  )g{Gz?rY   r   rU   gQ?gffffff?g?r  r  F),r   rD   copyr   r   numpyr}   r  torchvision.transformsr+   r   ultralytics.utilsr   r   ultralytics.utils.checksr   ultralytics.utils.instancer   ultralytics.utils.metricsr   ultralytics.utils.opsr	   utilsr   r   r   r(   r<   rW   r   r   r  r6  rB  r`  rt  r  r  r  r  r  r  r  r  r   r   r   <module>r     s      
   " . 2 0 . - 9#$ #$L\ \4*" *"ZV Vr *mf mf`( (V6 6rA AH? ?D3 3nQ% Q%hN@! )$X/ /dl l4 r   