def get_ann(img, gt_path):
    # h, w = img.shape[0:2]
    h, w = img.height, img.width
    lines = mmcv.list_from_file(gt_path)
    bboxes = []
    words = []
    for line in lines:
        line = line.encode('utf-8').decode('utf-8-sig')
        line = line.replace('\xef\xbb\xbf', '')

        gt = line.split(' ')

        w_ = np.float(gt[4])
        h_ = np.float(gt[5])
        x1 = np.float(gt[2]) + w_ / 2.0
        y1 = np.float(gt[3]) + h_ / 2.0
        theta = np.float(gt[6]) / math.pi * 180

        bbox = cv2.boxPoints(((x1, y1), (w_, h_), theta))
        # print(np.asarray(bbox.reshape(-1)))
        bbox = np.array(adjust_box_sort(np.asarray(
            bbox.reshape(-1)))) / ([w * 1.0, h * 1.0] * 4)
        # bbox = bbox.reshape(-1)

        bboxes.append(bbox)
        words.append('???')
    return np.array(bboxes), words
    def parse_mat(self, mat, image_id):
        """
        .mat file parser
        :param mat_path: (str), mat file path
        :return: (list), TextInstance
        """
        labels = []
        vertices = []
        if len(mat.shape) < 3:
            number = 1
        else:
            number = mat.shape[2]
        for cell in range(number):
            if number == 1:
                x1 = mat[0][0]
                x2 = mat[0][1]
                x3 = mat[0][2]
                x4 = mat[0][3]

                y1 = mat[1][0]
                y2 = mat[1][1]
                y3 = mat[1][2]
                y4 = mat[1][3]
            else:
                x1 = mat[0][0][cell]
                x2 = mat[0][1][cell]
                x3 = mat[0][2][cell]
                x4 = mat[0][3][cell]

                y1 = mat[1][0][cell]
                y2 = mat[1][1][cell]
                y3 = mat[1][2][cell]
                y4 = mat[1][3][cell]

            oriented_box = [
                int(x1),
                int(y1),
                int(x2),
                int(y2),
                int(x3),
                int(y3),
                int(x4),
                int(y4)
            ]
            oriented_box = adjust_box_sort(oriented_box)
            oriented_box = np.asarray(oriented_box)
            vertices.append(oriented_box)
            labels.append(1)

        return np.array(vertices), np.array(labels)
def extract_vertices(lines):
    '''extract vertices info from txt lines
    Input:
        lines   : list of string info
    Output:
        vertices: vertices of text regions <numpy.ndarray, (n,8)>
        labels  : 1->valid, 0->ignore, <numpy.ndarray, (n,)>
    '''
    labels = []
    vertices = []
    for line in lines:
        box = list(map(int, line.rstrip('\n').lstrip('\ufeff').split(',')[:8]))
        box = adjust_box_sort(box)
        vertices.append(box)
        label = 0 if '###' in line else 1
        labels.append(label)
    return np.array(vertices), np.array(labels)