import torch


def dbbox2roi(dbbox_list):
    """
    Convert a list of dbboxes to droi format.
    :param dbbox_list: (list[Tensor]): a list of dbboxes corresponding to a batch of images
    :return: Tensor: shape (n, 6) [batch_ind, x_ctr, y_ctr, w, h, angle]
    """
    drois_list = []
    for img_id, dbboxes in enumerate(dbbox_list):
        if dbboxes.size(0) > 0:
            img_inds = dbboxes.new_full((dbboxes.size(0), 1), img_id)
            drois = torch.cat([img_inds, dbboxes[:, :5]], dim=-1)
        else:
            drois = dbboxes.new_zeros((0, 6))

        drois_list.append(drois)
    drois = torch.cat(drois_list, 0)
    return drois