import torch


def convert_bbox_corners_to_centre_hw_torch(bbox_corners):
    """
    Convert bbox coordinates from [top left:(x1, y1), bot right: (x2, y2)]  to centre, height, width.
    x = rows/vertical axis, y = columns/horizontal axis
    :param bbox_corners: (B, 4) tensor of bounding box corners [x1, y1, x2, y2] in (vertical, horizontal) coordinates.
    :returns bbox_centres: (B, 2) tensor of bounding box centres in (vertical, horizontal) coordinates.
    :returns bbox_heights and bbox_widths: (B,) tensors of bounding box heights and widths
    """
    bbox_centres = torch.zeros(bbox_corners.shape[0], 2,
                               dtype=torch.float32, device=bbox_corners.device)
    bbox_centres[:, 0] = (bbox_corners[:, 0] + bbox_corners[:, 2]) / 2.0
    bbox_centres[:, 1] = (bbox_corners[:, 1] + bbox_corners[:, 3]) / 2.0
    bbox_heights = bbox_corners[:, 2] - bbox_corners[:, 0]
    bbox_widths = bbox_corners[:, 3] - bbox_corners[:, 1]

    return bbox_centres, bbox_heights, bbox_widths