from create_characters import load_test_set from create_classifier import load_classifier if len(argv) < 3: print 'Usage: python %s NEIGHBOURS BLUR_SCALE [ C GAMMA ]' % argv[0] exit(1) neighbours = int(argv[1]) blur_scale = float(argv[2]) # Load classifier if len(argv) > 4: c = float(argv[3]) gamma = float(argv[4]) classifier = load_classifier(neighbours, blur_scale, c=c, gamma=gamma, \ verbose=1) else: classifier = load_classifier(neighbours, blur_scale, verbose=1) # Load test set test_set = load_test_set(neighbours, blur_scale, verbose=1) # Classify each character in the test set, remembering all faulty # classified characters l = len(test_set) matches = 0 classified = [] for i, char in enumerate(test_set): prediction = classifier.classify(char, char.value)
for image in sorted(listdir(IMAGES_FOLDER + value)): f = IMAGES_FOLDER + value + "/" + image image = GrayscaleImage(f) char = Character(value, [], image) chars.append(char) i += 1 if i == count: br = True break if br: break # Load classifier (run create_classifier.py first) classifier = load_classifier(neighbours, blur_scale, verbose=1) # Measure the time it takes to recognize <count> characters start = time() for char in chars: # Normalize the character image char.image = NormalizedCharacterImage(image, blur=blur_scale, height=42) # Create the image's feature vector char.get_single_cell_feature_vector(neighbours) # Feed the feature vector to the classifier classifier.classify(char) elapsed = time() - start