forked from astutejoe/tesseract_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_training_text.py
More file actions
executable file
·50 lines (40 loc) · 1.32 KB
/
Copy pathsplit_training_text.py
File metadata and controls
executable file
·50 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import random
import pathlib
import subprocess
training_text_file = 'langdata/eng.training_text'
lines = []
with open(training_text_file, 'r', encoding="utf-8") as input_file:
for line in input_file.readlines():
lines.append(line.strip())
# output_directory = 'tesstrain/data/Apex-ground-truth'
output_directory = 'tesstrain/data/CourierETT-ground-truth'
if not os.path.exists(output_directory):
os.mkdir(output_directory)
random.shuffle(lines)
count = 100
lines = lines[:count]
line_count = 0
for line in lines:
training_text_file_name = pathlib.Path(training_text_file).stem
line_training_text = os.path.join(
output_directory, f'{training_text_file_name}_{line_count}.gt.txt')
with open(line_training_text, 'w', encoding="utf-8") as output_file:
output_file.writelines([line])
file_base_name = f'eng_{line_count}'
subprocess.run([
'text2image',
# '--font=Apex',
'--font=CourierETT',
f'--text={line_training_text}',
f'--outputbase={output_directory}/{file_base_name}',
'--max_pages=1',
'--strip_unrenderable_words',
'--leading=32',
'--xsize=3600',
'--ysize=480',
'--char_spacing=1.0',
'--exposure=0',
'--unicharset_file=langdata/eng.unicharset'
])
line_count += 1