changeset 273:7800be7bce66

changes in ttf2jpg and pycaptcha to load a file list with cPickle (instead of doing a listdir()) in order to have always the same list order from different machine (to reproduce generation)
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Sun, 21 Mar 2010 16:45:48 -0400
parents 716c99f4eb3a
children 44409b6652aa
files data_generation/transformations/pycaptcha/Captcha/File.py data_generation/transformations/ttf2jpg.py
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/data_generation/transformations/pycaptcha/Captcha/File.py	Wed Mar 17 16:41:51 2010 -0400
+++ b/data_generation/transformations/pycaptcha/Captcha/File.py	Sun Mar 21 16:45:48 2010 -0400
@@ -7,7 +7,7 @@
 # Copyright (C) 2004 Micah Dowty <micah@navi.cx>
 #
 
-import os, random
+import os, random, cPickle
 
 # Determine the data directory. This can be overridden after import-time if needed.
 dataDir = os.path.join(os.path.split(os.path.abspath(__file__))[0], "data")
@@ -41,7 +41,10 @@
             else:
                 path = os.path.join(dataDir, self.basePath, name)
             if os.path.isdir(path):
-                for content in os.listdir(path):
+                f = open(path + '/filelist.pkl')
+                filelist = cPickle.load(f)
+                f.close()
+                for content in filelist:
                     if self._checkExtension(content):
                         paths.append(os.path.join(path, content))
             else:
--- a/data_generation/transformations/ttf2jpg.py	Wed Mar 17 16:41:51 2010 -0400
+++ b/data_generation/transformations/ttf2jpg.py	Sun Mar 21 16:45:48 2010 -0400
@@ -10,6 +10,7 @@
 
 import sys, os, fnmatch, random
 import Image, ImageFont, ImageDraw, numpy
+import cPickle
 
 class ttf2jpg():
     def __init__(self, font_file = ''):
@@ -26,8 +27,9 @@
             self.char_list.append(chr(ord('A') + i) )
         for i in range(0,26):
             self.char_list.append(chr(ord('a') + i) )
-        files = os.listdir(self.font_dir)
-        self.font_files = fnmatch.filter(files, '*.ttf') + fnmatch.filter(files, '*.TTF')
+        f = open( self.font_dir + 'filelist.pkl' ,'r')
+        self.font_files = cPickle.load(f)
+        f.close()
 
     # get font name
     def get_settings_names(self):