U
    (dh	                     @   sX   d dl Z d dl mZ eedddZeedddZeeddd	Zeedd
dZdS )    N)Tensor)boxesreturnc           	      C   s\   |  d\}}}}|d|  }|d|  }|d|  }|d|  }tj||||fdd} | S )ad  
    Converts bounding boxes from (cx, cy, w, h) format to (x1, y1, x2, y2) format.
    (cx, cy) refers to center of bounding box
    (w, h) are width and height of bounding box
    Args:
        boxes (Tensor[N, 4]): boxes in (cx, cy, w, h) format which will be converted.

    Returns:
        boxes (Tensor(N, 4)): boxes in (x1, y1, x2, y2) format.
    g      ?ZdimZunbindtorchstack)	r   cxcywhx1y1x2y2 r   @/tmp/pip-unpacked-wheel-vx7f76es/torchvision/ops/_box_convert.py_box_cxcywh_to_xyxy   s    r   c           	      C   sT   |  d\}}}}|| d }|| d }|| }|| }tj||||fdd} | S )ah  
    Converts bounding boxes from (x1, y1, x2, y2) format to (cx, cy, w, h) format.
    (x1, y1) refer to top left of bounding box
    (x2, y2) refer to bottom right of bounding box
    Args:
        boxes (Tensor[N, 4]): boxes in (x1, y1, x2, y2) format which will be converted.

    Returns:
        boxes (Tensor(N, 4)): boxes in (cx, cy, w, h) format.
    r      r   r   )	r   r   r   r   r   r
   r   r   r   r   r   r   _box_xyxy_to_cxcywh   s    r   c                 C   s4   |  d\}}}}tj|||| || gdd} | S )aW  
    Converts bounding boxes from (x, y, w, h) format to (x1, y1, x2, y2) format.
    (x, y) refers to top left of bouding box.
    (w, h) refers to width and height of box.
    Args:
        boxes (Tensor[N, 4]): boxes in (x, y, w, h) which will be converted.

    Returns:
        boxes (Tensor[N, 4]): boxes in (x1, y1, x2, y2) format.
    r   r   r   )r   xyr   r   r   r   r   _box_xywh_to_xyxy2   s    r   c                 C   s<   |  d\}}}}|| }|| }tj||||fdd} | S )a]  
    Converts bounding boxes from (x1, y1, x2, y2) format to (x, y, w, h) format.
    (x1, y1) refer to top left of bounding box
    (x2, y2) refer to bottom right of bounding box
    Args:
        boxes (Tensor[N, 4]): boxes in (x1, y1, x2, y2) which will be converted.

    Returns:
        boxes (Tensor[N, 4]): boxes in (x, y, w, h) format.
    r   r   r   )r   r   r   r   r   r   r   r   r   r   _box_xyxy_to_xywhB   s
    r   )r   r   r   r   r   r   r   r   r   r   <module>   s
   