Skip to content

Commit 3414a65

Browse files
JulienCoutaultBelval
authored andcommitted
Add argument --font
1 parent 06d987b commit 3414a65

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

TextRecognitionDataGenerator/run.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os, errno
33
import random
44
import string
5+
import sys
56

67
from tqdm import tqdm
78
from string_generator import (
@@ -252,6 +253,13 @@ def parse_arguments():
252253
help="Apply a tight crop around the rendered text",
253254
default=False
254255
)
256+
parser.add_argument(
257+
"-ft",
258+
"--font",
259+
type=str,
260+
nargs="?",
261+
help="Define font to be used"
262+
)
255263

256264

257265
return parser.parse_args()
@@ -295,7 +303,13 @@ def main():
295303
lang_dict = load_dict(args.language)
296304

297305
# Create font (path) list
298-
fonts = load_fonts(args.language)
306+
if not args.font:
307+
fonts = load_fonts(args.language)
308+
else:
309+
if os.path.isfile(args.font):
310+
fonts = [args.font]
311+
else:
312+
sys.exit("Cannot open font")
299313

300314
# Creating synthetic sentences (or word)
301315
strings = []

tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,18 @@ def test_handwritten(self):
664664
self.assertTrue(len(os.listdir('tests/out/')) == 1)
665665
empty_directory('tests/out/')
666666

667+
def test_personalfont(self):
668+
args = ['python3', 'run.py', '--font', 'fonts/latin/Aller_Bd.ttf' , '-c', '1', '--output_dir', '../tests/out/']
669+
subprocess.Popen(args, cwd="TextRecognitionDataGenerator/").wait()
670+
self.assertTrue(len(os.listdir('tests/out/')) == 1)
671+
empty_directory('tests/out/')
672+
673+
def test_personalfont_unlocated(self):
674+
args = ['python3', 'run.py', '--font', 'fonts/latin/unlocatedFont.ttf' , '-c', '1', '--output_dir', '../tests/out/']
675+
subprocess.Popen(args, cwd="TextRecognitionDataGenerator/").wait()
676+
self.assertTrue(len(os.listdir('tests/out/')) == 0)
677+
empty_directory('tests/out/')
678+
667679
# def test_word_count(self):
668680
# args = ['python3', 'run.py', '-c', '1', '-w', '5']
669681
# subprocess.Popen(args, cwd="TextRecognitionDataGenerator/").wait()

0 commit comments

Comments
 (0)