예제 #1
0
    def load_gt(self, gt_path):
        lines = open(gt_path, encoding='utf-8').readlines()
        bboxes = []
        words = []
        for line in lines:
            ori_box = line.strip().encode('utf-8').decode('utf-8-sig').split(
                ',')
            box = [int(ori_box[j]) for j in range(8)]
            word = ori_box[8:]
            word = ','.join(word)
            box = np.array(box, np.int32).reshape(4, 2)
            if word == '###':
                words.append('###')
                bboxes.append(box)
                continue
            area, p0, p3, p2, p1, _, _ = mep(box)

            bbox = np.array([p0, p1, p2, p3])
            distance = 10000000
            index = 0
            for i in range(4):
                d = np.linalg.norm(box[0] - bbox[i])
                if distance > d:
                    index = i
                    distance = d
            new_box = []
            for i in range(index, index + 4):
                new_box.append(bbox[i % 4])
            new_box = np.array(new_box)
            bboxes.append(np.array(new_box))
            words.append(word)
        return bboxes, words
예제 #2
0
def read_gt(txt, type):
    label = []
    with open(txt) as f:
        gts = f.readlines()

        for gt in gts:
            bboxes = []
            words = []
            if type == '2013':
                ori_box = gt.strip().encode('utf-8').decode('utf-8-sig').split(
                    ' ')
                if len(ori_box) == 1:
                    continue
                box = [int(ori_box[j + 1]) for j in range(8)]
                word = ori_box[-1]
                word = word.replace('"', '')
                if not word.isalpha():
                    word = ' '
            else:
                ori_box = gt.strip().encode('utf-8').decode('utf-8-sig').split(
                    ',')
                box = [int(ori_box[j]) for j in range(8)]
                word = ori_box[-1]
                word = ','.join(word)
            box = np.array(box, np.int32).reshape(4, 2)
            if word == '###':
                words.append('###')
                bboxes.append(box)
                continue
            if len(word.strip()) == 0:
                continue

            try:
                # mep 과정에서 overflow 발생
                area, p0, p3, p2, p1, _, _ = mep(box)
            except Exception as e:
                continue

            bbox = np.array([p0, p1, p2, p3])
            distance = 10000000
            index = 0
            for i in range(4):
                d = np.linalg.norm(box[0] - bbox[i])
                if distance > d:
                    index = i
                    distance = d
            new_box = []
            for i in range(index, index + 4):
                new_box.append(bbox[i % 4])
            new_box = np.array(new_box)
            label.append((new_box, word))
    return label
예제 #3
0
    def load_gt(self, gt_path):
        lines = open(gt_path, encoding='utf-8').readlines()
        bboxes = []
        words = []
        for line in lines:
            ori_box = line.strip().split()
            box = [int(ori_box[j]) for j in range(4)]
            box = [
                box[0], box[1], box[2], box[1], box[2], box[3], box[0], box[3]
            ]
            word = ori_box[4:]
            word = [s.strip('\"') for s in word]
            word = ','.join(word)
            box = np.array(box, np.int32).reshape(4, 2)
            if word == '###':
                words.append('###')
                bboxes.append(box)
                continue
            if len(word.strip()) == 0:
                continue

            try:
                area, p0, p3, p2, p1, _, _ = mep(box)
            except Exception as e:
                print(e, gt_path)

            bbox = np.array([p0, p1, p2, p3])
            distance = 10000000
            index = 0
            for i in range(4):
                d = np.linalg.norm(box[0] - bbox[i])
                if distance > d:
                    index = i
                    distance = d
            new_box = []
            for i in range(index, index + 4):
                new_box.append(bbox[i % 4])
            new_box = np.array(new_box)
            bboxes.append(new_box)
            words.append(word)
        return bboxes, words