forked from WenmuZhou/OCR_DataSet
-
Notifications
You must be signed in to change notification settings - Fork 1
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
24 changed files
with
482 additions
and
27 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
File renamed without changes.
File renamed without changes.
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,46 @@ | ||
# -*- 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(',') | ||
# 字符串级别的信息 | ||
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\MTWI2018\detection\gt' | ||
img_folder = r'D:\dataset\MTWI2018\detection\imgs' | ||
save_path = r'D:\dataset\MTWI2018\detection\train.json' | ||
cvt(gt_path, save_path, img_folder) |
File renamed without changes.
File renamed without changes.
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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2020/3/23 9:29 | ||
# @Author : zhoujun | ||
import os | ||
import pathlib | ||
import numpy as np | ||
from tqdm import tqdm | ||
import scipy.io as sio | ||
from convert.utils import save | ||
|
||
|
||
class SynthTextDataset(): | ||
def __init__(self, img_folder: str, gt_path: str): | ||
self.img_folder = img_folder | ||
if not os.path.exists(self.img_folder): | ||
raise FileNotFoundError('Dataset folder is not exist.') | ||
|
||
self.targetFilePath = gt_path | ||
if not os.path.exists(self.targetFilePath): | ||
raise FileExistsError('Target file is not exist.') | ||
targets = {} | ||
sio.loadmat(self.targetFilePath, targets, squeeze_me=True, struct_as_record=False, | ||
variable_names=['imnames', 'wordBB', 'txt']) | ||
|
||
self.imageNames = targets['imnames'] | ||
self.wordBBoxes = targets['wordBB'] | ||
self.transcripts = targets['txt'] | ||
|
||
def cvt(self): | ||
gt_dict = {'data_root': self.img_folder} | ||
data_list = [] | ||
pbar = tqdm(total=len(self.imageNames)) | ||
for imageName, wordBBoxes, texts in zip(self.imageNames, self.wordBBoxes, self.transcripts): | ||
wordBBoxes = np.expand_dims(wordBBoxes, axis=2) if (wordBBoxes.ndim == 2) else wordBBoxes | ||
_, _, numOfWords = wordBBoxes.shape | ||
text_polys = wordBBoxes.reshape([8, numOfWords], order='F').T # num_words * 8 | ||
text_polys = text_polys.reshape(numOfWords, 4, 2) # num_of_words * 4 * 2 | ||
transcripts = [word for line in texts for word in line.split()] | ||
if numOfWords != len(transcripts): | ||
continue | ||
cur_gt = {'img_name': imageName, 'annotations': []} | ||
for polygon, text in zip(text_polys, transcripts): | ||
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['text'] = text | ||
cur_line_gt['polygon'] = polygon.tolist() | ||
cur_line_gt['illegibility'] = text in ['###', '*'] | ||
cur_gt['annotations'].append(cur_line_gt) | ||
data_list.append(cur_gt) | ||
pbar.update(1) | ||
pbar.close() | ||
gt_dict['data_list'] = data_list | ||
save(gt_dict, save_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
img_folder = r'D:\dataset\SynthText800k\detection\imgs' | ||
gt_path = r'D:\dataset\SynthText800k\detection\gt.mat' | ||
save_path = r'D:\dataset\SynthText800k\detection\train1.json' | ||
synth_dataset = SynthTextDataset(img_folder, gt_path) | ||
synth_dataset.cvt() |
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,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2020/3/24 11:09 | ||
# @Author : zhoujun |
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,45 @@ | ||
# -*- 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(save_path, img_folder): | ||
""" | ||
将icdar2015格式的gt转换为json格式 | ||
:param gt_path: | ||
:param save_path: | ||
:return: | ||
""" | ||
gt_dict = {'data_root': img_folder} | ||
data_list = [] | ||
for img_path in tqdm(get_file_list(img_folder, p_postfix=['.jpg'])): | ||
img_path = pathlib.Path(img_path) | ||
gt_path = pathlib.Path(img_folder) / img_path.name.replace('.jpg', '.txt') | ||
content = load(gt_path) | ||
cur_gt = {'img_name': img_path.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(',') | ||
# 字符串级别的信息 | ||
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][1:-1] | ||
cur_line_gt['illegibility'] = True if line[8] == '1' 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__': | ||
img_folder = r'D:\dataset\icdar2017rctw\detection\imgs' | ||
save_path = r'D:\dataset\icdar2017rctw\detection\train.json' | ||
cvt(save_path, img_folder) |
File renamed without changes.
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,36 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2020/3/24 11:26 | ||
# @Author : zhoujun | ||
|
||
import os | ||
from PIL import Image | ||
from tqdm import tqdm | ||
import matplotlib.pyplot as plt | ||
|
||
# 支持中文 | ||
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 | ||
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 | ||
from convert.utils import load, save | ||
|
||
def cvt(gt_path, save_path, img_folder): | ||
content = load(gt_path) | ||
file_list = [] | ||
for i,line in tqdm(enumerate(content)): | ||
try: | ||
line = line.split('.jpg ') | ||
img_path = os.path.join(img_folder, line[-2]) | ||
file_list.append(img_path + '.jpg' + '\t' + line[-1] + '\t' + 'Chinese') | ||
# img = Image.open(img_path) | ||
# plt.title(line[-1]) | ||
# plt.imshow(img) | ||
# plt.show() | ||
except: | ||
a = 1 | ||
save(file_list, save_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
img_folder = r'D:\dataset\360w\train_images' | ||
gt_path = r'D:\BaiduNetdiskDownload\360_train.txt' | ||
save_path = r'D:\BaiduNetdiskDownload\train.txt' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2020/3/24 11:10 | ||
# @Author : zhoujun |
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,35 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2020/3/24 11:10 | ||
# @Author : zhoujun | ||
import os | ||
from PIL import Image | ||
from tqdm import tqdm | ||
import matplotlib.pyplot as plt | ||
|
||
# 支持中文 | ||
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 | ||
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 | ||
from convert.utils import load, save | ||
|
||
|
||
def cvt(gt_path, save_path, img_folder): | ||
content = load(gt_path) | ||
file_list = [] | ||
for line in tqdm(content): | ||
line = line.split('\t') | ||
img_path = os.path.join(img_folder, line[-2]) | ||
if not os.path.exists(img_path): | ||
print(img_path) | ||
file_list.append(img_path + '\t' + line[-1] + '\t' + 'Chinese') | ||
# img = Image.open(img_path) | ||
# plt.title(line[-1]) | ||
# plt.imshow(img) | ||
# plt.show() | ||
save(file_list, save_path) | ||
|
||
|
||
if __name__ == '__main__': | ||
img_folder = r'D:\dataset\百度中文场景文字识别\train_images' | ||
gt_path = r'D:\dataset\百度中文场景文字识别\train.list' | ||
save_path = r'D:\dataset\百度中文场景文字识别\train.txt' | ||
cvt(gt_path, save_path, img_folder) |
Oops, something went wrong.