annotate data_generation/transformations/pycaptcha/Facade.py @ 608:456a8fb9829e

spotlight
author Yoshua Bengio <bengioy@iro.umontreal.ca>
date Wed, 01 Dec 2010 18:03:11 -0500
parents ff26436d42d6
children
rev   line source
87
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
1 #!/usr/bin/env python
174
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 167
diff changeset
2 import sys, os
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 167
diff changeset
3 curdir = os.path.dirname(__file__)
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 167
diff changeset
4 if curdir != '':
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 167
diff changeset
5 sys.path.append(curdir)
87
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
6
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
7 from Captcha.Visual.Tests import PseudoGimpy, AngryGimpy
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
8 import numpy
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
9
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
10 # Une fonction simple pour generer un captcha
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
11 # ease : represente la difficulte du captcha a generer
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
12 # 0 = facile et 1 (ou autre chose) = difficile
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
13 #solution : specifie si on veut en retour un array numpy representant
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
14 #l image ou un tuple contenant l'array et la solution du captcha.
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
15
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
16 # Des fontes additionnelles peuvent etre ajoutees au dossier pyCaptcha/Captcha/data/fonts/others
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
17 # Le programme choisit une fonte aleatoirement dans ce dossier ainsi que le dossir vera.
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
18
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
19
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
20 def generateCaptcha (ease=0, solution=0):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
21
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
22 if ease == 1:
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
23 g = AngryGimpy()
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
24
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
25 else:
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
26 g = PseudoGimpy()
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
27
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
28 i = g.render()
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
29 a = numpy.asarray(i)
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
30
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
31 if solution == 0:
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
32 return a
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
33
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
34 else :
126
66b9513b578f Fixed bug in pycaptcha/Facade.py
boulanni <nicolas_boulanger@hotmail.com>
parents: 87
diff changeset
35 return (a, g.solutions)