diff --git a/README.md b/README.md index 5bea6c9..a68ad18 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ - [x] MLT2019 - [x] COCO-Text_v2 - [x] ReCTS - - [ ] SROIE - - [ ] ArT - - [ ] LSVT + - [x] SROIE + - [x] ArT + - [x] LSVT - [ ] Synth800k - [ ] icdar2017rctw - [ ] Synth800k diff --git a/convert/ArtS2json.py b/convert/ArtS2json.py new file mode 100644 index 0000000..3a29b0a --- /dev/null +++ b/convert/ArtS2json.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# @Time : 2020/3/18 14:12 +# @Author : zhoujun +""" +将icdar2015数据集转换为统一格式 +""" +import os +from tqdm import tqdm +from convert.utils import load, save + + +def cvt_det(gt_path, save_path, img_folder): + """ + 将icdar2015格式的gt转换为json格式 + :param gt_path: + :param save_path: + :return: + """ + gt_dict = {'data_root': img_folder} + data_list = [] + origin_gt = load(gt_path) + for img_name, gt in tqdm(origin_gt.items()): + cur_gt = {'img_name': img_name + '.jpg', 'annotations': []} + for line in gt: + cur_line_gt = {'polygon': [], 'text': '', 'illegibility': False, 'language': 'Latin'} + chars_gt = [{'polygon': [], 'char': '', 'illegibility': False, 'language': 'Latin'}] + cur_line_gt['chars'] = chars_gt + # 字符串级别的信息 + cur_line_gt['polygon'] = line['points'] + cur_line_gt['text'] = line['transcription'] + cur_line_gt['illegibility'] = line['illegibility'] + cur_line_gt['language'] = line['language'] + cur_gt['annotations'].append(cur_line_gt) + data_list.append(cur_gt) + gt_dict['data_list'] = data_list + save(gt_dict, save_path) + + +def cvt_rec(gt_path, save_path, img_folder): + origin_gt = load(gt_path) + file_list = [] + for img_name, gt in tqdm(origin_gt.items()): + assert len(gt) == 1 + gt = gt[0] + img_path = os.path.join(img_folder, img_name + '.jpg') + file_list.append(img_path + '\t' + gt['transcription'] + '\t' + gt['language']) + save(file_list, save_path) + + +if __name__ == '__main__': + gt_path = r'D:\dataset\Art\detection\gt\train_labels.json' + img_folder = r'D:\dataset\Art\detection\train_images' + save_path = r'D:\dataset\Art\detection\train.json' + cvt_det(gt_path, save_path, img_folder) diff --git a/convert/LSVT2json.py b/convert/LSVT2json.py new file mode 100644 index 0000000..6c28d7c --- /dev/null +++ b/convert/LSVT2json.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# @Time : 2020/3/18 14:12 +# @Author : zhoujun +""" +将icdar2015数据集转换为统一格式 +""" +import os +from tqdm import tqdm +from convert.utils import load, save + + +def cvt(gt_path, save_path, img_folder): + """ + 将icdar2015格式的gt转换为json格式 + :param gt_path: + :param save_path: + :return: + """ + gt_dict = {'data_root': img_folder} + data_list = [] + origin_gt = load(gt_path) + for img_name, gt in tqdm(origin_gt.items()): + cur_gt = {'img_name': img_name + '.jpg', 'annotations': []} + for line in gt: + cur_line_gt = {'polygon': [], 'text': '', 'illegibility': False, 'language': 'Latin'} + chars_gt = [{'polygon': [], 'char': '', 'illegibility': False, 'language': 'Latin'}] + cur_line_gt['chars'] = chars_gt + # 字符串级别的信息 + cur_line_gt['polygon'] = line['points'] + cur_line_gt['text'] = line['transcription'] + cur_line_gt['illegibility'] = line['illegibility'] + cur_gt['annotations'].append(cur_line_gt) + data_list.append(cur_gt) + gt_dict['data_list'] = data_list + save(gt_dict, save_path) + + +if __name__ == '__main__': + gt_path = r'D:\dataset\LSVT\detection\train_full_labels.json' + img_folder = r'D:\dataset\LSVT\detection\imgs' + save_path = r'D:\dataset\LSVT\detection\train.json' + cvt(gt_path, save_path, img_folder) diff --git a/convert/RcCTS2json.py b/convert/RcCTS2json.py index 1776173..d5ea3e6 100644 --- a/convert/RcCTS2json.py +++ b/convert/RcCTS2json.py @@ -16,7 +16,7 @@ def decode_chars(char_list): text_list = [] for char_dict in char_list: polygon_list.append(np.array(char_dict['points']).reshape(-1, 2).tolist()) - illegibility_list.append(char_dict['ignore']) + illegibility_list.append(True if char_dict['ignore'] == 1 else False) text_list.append(char_dict['transcription']) return polygon_list, illegibility_list, text_list diff --git a/convert/check_json.py b/convert/check_json.py index c4e4477..5a32164 100644 --- a/convert/check_json.py +++ b/convert/check_json.py @@ -10,9 +10,11 @@ from convert.utils import show_bbox_on_image, load_gt if __name__ == '__main__': - json_path = r'D:\dataset\ReCTS\detection\train.json' + json_path = r'D:\dataset\LSVT\detection\train.json' data = load_gt(json_path) for img_path, gt in data.items(): + print(gt['illegibility_list']) + print(gt['texts']) img = Image.open(img_path) img = show_bbox_on_image(img, gt['polygons'], gt['texts']) plt.imshow(img) diff --git a/convert/crop_rec.py b/convert/crop_rec.py index cc3024b..0c92c96 100644 --- a/convert/crop_rec.py +++ b/convert/crop_rec.py @@ -65,10 +65,7 @@ def four_point_transform(image, pts): return warped -if __name__ == '__main__': - json_path = r'D:\dataset\ReCTS\detection\train.json' - save_path = r'D:\dataset\ReCTS\recognition\train' - gt_path = pathlib.Path(save_path).parent / 'train.txt' +def crop(save_gt_path, json_path, save_path): if os.path.exists(save_path): shutil.rmtree(save_path, ignore_errors=True) os.makedirs(save_path, exist_ok=True) @@ -79,7 +76,7 @@ def four_point_transform(image, pts): img_name = pathlib.Path(img_path).stem for i, (polygon, text, illegibility, language) in enumerate( zip(gt['polygons'], gt['texts'], gt['illegibility_list'], gt['language_list'])): - if illegibility or '###' in text or '*' in text: + if illegibility: continue polygon = np.array(polygon) roi_img_save_path = os.path.join(save_path, '{}_{}.jpg'.format(img_name, i)) @@ -99,4 +96,11 @@ def four_point_transform(image, pts): # plt.title(text) # plt.imshow(roi_img) # plt.show() - save(file_list, gt_path) + save(file_list, save_gt_path) + + +if __name__ == '__main__': + json_path = r'D:\dataset\LSVT\detection\train.json' + save_path = r'D:\dataset\LSVT\recognition\train' + gt_path = pathlib.Path(save_path).parent / 'train.txt' + crop(gt_path, json_path, save_path) diff --git a/convert/mlt20192json.py b/convert/mlt20192json.py index 1b95393..91a848c 100644 --- a/convert/mlt20192json.py +++ b/convert/mlt20192json.py @@ -22,7 +22,7 @@ def cvt(gt_path, save_path, img_folder): for file_path in tqdm(get_file_list(gt_path, p_postfix=['.txt'])): content = load(file_path) file_path = pathlib.Path(file_path) - img_name = file_path.name.replace('gt_', '').replace('.txt', '.jpg') + img_name = file_path.name.replace('.txt', '.jpg') cur_gt = {'img_name': img_name, 'annotations': []} for line in content: cur_line_gt = {'polygon': [], 'text': '', 'illegibility': False, 'language': 'Latin'} diff --git a/convert/sroie2json.py b/convert/sroie2json.py new file mode 100644 index 0000000..526c781 --- /dev/null +++ b/convert/sroie2json.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# @Time : 2020/3/18 14:12 +# @Author : zhoujun +""" +将icdar2015数据集转换为统一格式 +""" +import pathlib +from tqdm import tqdm +from convert.utils import load, save, get_file_list + + +def cvt(gt_path, save_path, img_folder): + """ + 将icdar2015格式的gt转换为json格式 + :param gt_path: + :param save_path: + :return: + """ + gt_dict = {'data_root': img_folder} + data_list = [] + for file_path in tqdm(get_file_list(gt_path, p_postfix=['.txt'])): + content = load(file_path) + file_path = pathlib.Path(file_path) + img_name = file_path.name.replace('.txt', '.jpg') + cur_gt = {'img_name': img_name, 'annotations': []} + for line in content: + cur_line_gt = {'polygon': [], 'text': '', 'illegibility': False, 'language': 'Latin'} + chars_gt = [{'polygon': [], 'char': '', 'illegibility': False, 'language': 'Latin'}] + cur_line_gt['chars'] = chars_gt + line = line.split(',') + if len(line) < 9: + continue + # 字符串级别的信息 + x1, y1, x2, y2, x3, y3, x4, y4 = list(map(float, line[:8])) + cur_line_gt['polygon'] = [[x1, y1], [x2, y2], [x3, y3], [x4, y4]] + cur_line_gt['text'] = line[-1] + cur_line_gt['illegibility'] = True if cur_line_gt['text'] == '*' or cur_line_gt['text'] == '###' else False + cur_gt['annotations'].append(cur_line_gt) + data_list.append(cur_gt) + gt_dict['data_list'] = data_list + save(gt_dict, save_path) + + +if __name__ == '__main__': + gt_path = r'D:\dataset\SROIE2019\detection\test\gt' + img_folder = r'D:\dataset\SROIE2019\detection\test\imgs' + save_path = r'D:\dataset\SROIE2019\detection\test.json' + cvt(gt_path, save_path, img_folder)