forked from WenmuZhou/OCR_DataSet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |