changeset 128:ccce06590e64

Added captcha support in pipeline.py
author boulanni <nicolas_boulanger@hotmail.com>
date Thu, 18 Feb 2010 14:27:49 -0500
parents 3f85e8c58a9f
children 38929c29b602
files transformations/pipeline.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/transformations/pipeline.py	Thu Feb 18 14:16:54 2010 -0500
+++ b/transformations/pipeline.py	Thu Feb 18 14:27:49 2010 -0500
@@ -55,6 +55,7 @@
 from add_background_image import AddBackground
 from affine_transform import AffineTransformation
 from ttf2jpg import ttf2jpg
+from ..pycaptcha.Facade import generateCaptcha
 
 if DEBUG:
     from visualizer import Visualizer
@@ -219,13 +220,15 @@
         ocr_img = ft.read(nist.ocr_data)
         ocr_labels = ft.read(nist.ocr_labels)
     ttf = ttf2jpg()
+    L = [chr(ord('0')+x) for x in range(10)] + [chr(ord('A')+x) for x in range(26)] + [chr(ord('a')+x) for x in range(26)]
 
     for i in xrange(num_img):
         r = numpy.random.rand()
         if r <= prob_font:
             yield ttf.generate_image()
         elif r <= prob_font + prob_captcha:
-            pass #get captcha
+            (arr, charac) = generateCaptcha(0,1)
+            yield arr.astype(numpy.float32)/255, L.index(charac)
         elif r <= prob_font + prob_captcha + prob_ocr:
             j = numpy.random.randint(len(ocr_labels))
             yield ocr_img[j].astype(numpy.float32)/255, ocr_labels[j]