Ejemplo n.º 1
0
    def parse_txt(gt_path):
        """
        .mat file parser
        :param gt_path: (str), mat file path
        :return: (list), TextInstance
        """
        lines = read_lines(gt_path+".txt")
        polygons = []
        for line in lines:
            line = strs.remove_all(line.strip('\ufeff'), '\xef\xbb\xbf')
            gt = line.split(',')
            x1, y1, x2, y2, x3, y3, x4, y4 = list(map(int, gt[:8]))
            xx = [x1, x2, x3, x4]
            yy = [y1, y2, y3, y4]

            label = gt[-1].strip().replace("###", "#")

            pts = np.stack([xx, yy]).T.astype(np.int32)
            # d1 = norm2(pts[0] - pts[1])
            # d2 = norm2(pts[1] - pts[2])
            # d3 = norm2(pts[2] - pts[3])
            # d4 = norm2(pts[3] - pts[0])
            # if min([d1, d2, d3, d4]) < 2:
            #     continue
            polygons.append(TextInstance(pts, 'c', label))

        return polygons
Ejemplo n.º 2
0
 def parse_carve_txt(gt_path):
     """
     .mat file parser
     :param gt_path: (str), mat file path
     :return: (list), TextInstance
     """
     lines = libio.read_lines(gt_path + ".txt")
     polygons = []
     for line in lines:
         line = strs.remove_all(line, '\xef\xbb\xbf')
         gt = line.split(',')
         xx = gt[0].replace("x: ", "").replace("[[", "").replace("]]", "").lstrip().rstrip()
         yy = gt[1].replace("y: ", "").replace("[[", "").replace("]]", "").lstrip().rstrip()
         try:
             xx = [int(x) for x in re.split(r" *", xx)]
             yy = [int(y) for y in re.split(r" *", yy)]
         except:
             xx = [int(x) for x in re.split(r" +", xx)]
             yy = [int(y) for y in re.split(r" +", yy)]
         if len(xx) < 4 or len(yy) < 4:  # too few points
             continue
         text = gt[-1].split('\'')[1]
         try:
             ori = gt[-2].split('\'')[1]
         except:
             ori = 'c'
         pts = np.stack([xx, yy]).T.astype(np.int32)
         polygons.append(TextInstance(pts, ori, text))
     # print(polygon)
     return polygons