(xyxy)
Convert [x1 y1 x2 y2] box format to [x1 y1 w h] format.
Convert [x1 y1 x2 y2] box format to [x1 y1 w h] format.
Convert [ x1 y1 x2 y2 ] box format to [ x1 y1 w h ] format .
def xyxy_to_xywh(xyxy):
    """Convert [x1 y1 x2 y2] box format to [x1 y1 w h] format."""
    if isinstance(xyxy, (list, tuple)):
        # Single box given as a list of coordinates
        assert len(xyxy) == 4
        x1, y1 = xyxy[0], xyxy[1]
        w = xyxy[2] - x1 + 1
        h = xyxy[3] - y1 + 1
        return (x1, y1, w, h)
    elif isinstance(xyxy, np.ndarray):
        # Multiple boxes given as a 2D ndarray
        return np.hstack((xyxy[:, 0:2], xyxy[:, 2:4] - xyxy[:, 0:2] + 1))
    else:
        raise TypeError('Argument xyxy must be a list, tuple, or numpy array.')
def xyxy_to_xywh ( xyxy ) : if isinstance ( xyxy , ( list , tuple ) ) : # Single box given as a list of coordinates assert len ( xyxy ) == 4 x1 , y1 = xyxy [ 0 ] , xyxy [ 1 ] w = xyxy [ 2 ] - x1 + 1 h = xyxy [ 3 ] - y1 + 1 return ( x1 , y1 , w , h ) elif isinstance ( xyxy , np . ndarray ) : # Multiple boxes given as a 2D ndarray return np . hstack ( ( xyxy [ : , 0 : 2 ] , xyxy [ : , 2 : 4 ] - xyxy [ : , 0 : 2 ] + 1 ) ) else : raise TypeError ( 'Argument xyxy must be a list, tuple, or numpy array.' )