Exemplo n.º 1
0
def handlePuzzle(imageFilename, vectorSet):
    print >>sys.stderr, "Loading %s" % imageFilename
    digits = mytry.processImage(imageFilename, interactive=False)
    labels = mytry.readLabels(imageFilename + ".labels")
    for ((i,j), im) in digits:
        label = labels[j][i]
        if label == ' ':
            print >>sys.stderr, "Warning, cell (%d,%d) not empty but labeled as such" % (i,j)
            continue

        vectorSet.append((label, list((convert.cvImg2np(im)/255).flat)))
Exemplo n.º 2
0
def main():
    if len(sys.argv) != 3:
        sys.stderr.write("Usage: %s trainingSet puzzle\n" % sys.argv[0])
        sys.exit(1)
    classifier = KNNClassifier(sys.argv[1])
    digits = mytry.processImage(sys.argv[2], interactive=False)
    res = [[' ' for i in range(9)] for j in range(9)]
    for ((i,j), im) in digits:
        # convert to same format as used in extractFeatures
        # TODO: this should already be returned from processImage
        im = list((convert.cvImg2np(im)/255).flat)
    
        label = classifier.classify(im)
        res[j][i] = label
        
            
    for j, line in enumerate(res):
        if j > 0 and j % 3 == 0:
            sys.stdout.write("------+------+------\n")
        for i, label in enumerate(line):
            if i > 0 and i % 3 == 0:
                sys.stdout.write("|")
            sys.stdout.write(" " + label)
        sys.stdout.write("\n")