Mercurial > ift6266
changeset 109:9c45e0071b52
Adapté le générateur d'images de fontes pour utiliser en amont du pipeline
author | boulanni <nicolas_boulanger@hotmail.com> |
---|---|
date | Tue, 16 Feb 2010 13:10:06 -0500 |
parents | a7cd8dd3221c |
children | 93b4b84d86cf |
files | transformations/pipeline.py transformations/ttf2jpg.py |
diffstat | 2 files changed, 11 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/transformations/pipeline.py Mon Feb 15 16:17:48 2010 -0500 +++ b/transformations/pipeline.py Tue Feb 16 13:10:06 2010 -0500 @@ -54,6 +54,7 @@ from Occlusion import Occlusion from add_background_image import AddBackground from affine_transform import AffineTransformation +from ttf2jpg import ttf2jpg if DEBUG: from visualizer import Visualizer @@ -211,11 +212,12 @@ if prob_ocr: ocr_img = ft.read(nist.ocr_data) ocr_labels = ft.read(nist.ocr_labels) + ttf = ttf2jpg() for i in xrange(num_img): r = numpy.random.rand() if r <= prob_font: - pass #get font + yield ttf.generate_image() elif r <= prob_font + prob_captcha: pass #get captcha elif r <= prob_font + prob_captcha + prob_ocr:
--- a/transformations/ttf2jpg.py Mon Feb 15 16:17:48 2010 -0500 +++ b/transformations/ttf2jpg.py Tue Feb 16 13:10:06 2010 -0500 @@ -15,17 +15,17 @@ def __init__(self, font_file = ''): self.w = 32 self.h = 32 - self.font_dir = '/usr/share/fonts/truetype/ttf-liberation/' + self.font_dir = '/data/lisa/data/ift6266h10/fonts/windows7/' self.font_file = font_file self.image_dir = './images/' self.pattern = '*.ttf' self.char_list = [] + for i in range(0,10): + self.char_list.append(chr(ord('0') + i) ) + for i in range(0,26): + self.char_list.append(chr(ord('A') + i) ) for i in range(0,26): self.char_list.append(chr(ord('a') + i) ) - for i in range(0,26): - self.char_list.append(chr(ord('A') + i) ) - for i in range(0,10): - self.char_list.append(chr(ord('0') + i) ) # get font name def get_settings_names(self): @@ -85,7 +85,7 @@ def generate_image(self): self.set_random_font() i = random.randint(0, len(self.char_list) - 1) - return self.generate_image_from_char(self.char_list[i]) + return self.generate_image_from_char(self.char_list[i]), i # test method, create character images for all fonts in "font_dir" in dir "image_dir" def test(self): @@ -117,5 +117,5 @@ myttf2jpg = ttf2jpg() #myttf2jpg.test() - image = myttf2jpg.generate_image() - myttf2jpg.save_image(image, '') \ No newline at end of file + image, i = myttf2jpg.generate_image() + myttf2jpg.save_image(image, '')