예제 #1
0
def main():
    image = Image.open(sys.argv[1]).convert("L")
    num_separator = DigitSeparator(image)
    for i,digit in enumerate(num_separator.get_digits()):
        img_name = '%s-%d.jpg' % (os.path.basename(sys.argv[1]), i)
        with open(os.path.join(sys.argv[2],img_name), 'w') as f:
            digit.image.save(f, 'JPEG')
예제 #2
0
 def fit(self, x, y):
     digits = []
     labels = []
     for image, param_labels in zip(x, y):
         separator = DigitSeparator(image)
         digits.extend(map(self.feature_extractor, separator.get_digits()))
         labels.extend(param_labels)
     self.vectorizer = DictVectorizer()
     train_array = self.vectorizer.fit_transform(digits).toarray()
     self.engine.fit(train_array, labels)
예제 #3
0
 def fit(self, x, y):
     digits = []
     labels = []
     for image,param_labels in zip(x,y):
         separator = DigitSeparator(image)
         digits.extend(map(self.feature_extractor, separator.get_digits()))
         labels.extend(param_labels)
     self.vectorizer = DictVectorizer()
     train_array = self.vectorizer.fit_transform(digits).toarray()
     self.engine.fit(train_array, labels)
예제 #4
0
 def __make_prediction(self, image):
     separator = DigitSeparator(image)
     features = map(self.feature_extractor, separator.get_digits())
     digits = self.vectorizer.transform(features).toarray()
     labels = self.engine.predict(digits)
     return ''.join(map(lambda x: '%d' % x, labels))
예제 #5
0
 def __make_prediction(self, image):
     separator = DigitSeparator(image) 
     features = map(self.feature_extractor, separator.get_digits())
     digits = self.vectorizer.transform(features).toarray()
     labels = self.engine.predict(digits)
     return ''.join(map(lambda x: '%d'%x, labels))