Example #1
0
        # from ~69% to 75% in one test.
        #if char in 'Iil':
        #    c /= 2.0
        return c

    def rankings(self, limit=None, ignore_case=True):
        r = sorted(self._sums, key=self.certainty, reverse=True)
        return self.filter_rankings(r, limit, ignore_case)

def test(image, char=None):
    classifications = MaskClassifications()
    m1 = make_mask(image, width=mask_table.width, height=mask_table.height)
    for c, m2 in mask_table.masks.items():
        s = cmp_masks(m1, m2)
        classifications.add(c, s)

    return classifications


if __name__ == '__main__':
    import sys
    args = sys.argv[1:]
    if len(args) == 1:
        i = cv.LoadImageM(sys.argv[1], cv.CV_LOAD_IMAGE_GRAYSCALE)
        classifications = test(i)
        rankings = classifications.rankings(limit=4)
        for r in rankings:
            print "guess = %s; certainty = %.4f" % (r, classifications.certainty(r))
    else:
        score_files(args, test)
Example #2
0
    def rankings(self, limit=None, ignore_case=True):
        r = sorted(self._certainties, key=self.certainty, reverse=True)
        return self.filter_rankings(r, limit, ignore_case)

class Combiner(object):

    def __init__(self, tests):
        self._tests = tests

    def test(self, image, char=None):
        classifications = CombinedClassifications()
        for test in self._tests:
            classifications.add(test(image, char=char))

        return classifications


if __name__ == '__main__':
    import sys
    args = sys.argv[1:]
    knn_test = KNNTest(data_path)
    c = Combiner([cont_test, mask_test, knn_test.test])
    if len(args) == 1:
        i = cv.LoadImageM(sys.argv[1], cv.CV_LOAD_IMAGE_GRAYSCALE)
        classifications = c.test(i)
        rankings = classifications.rankings(limit=4)
        for r in rankings:
            print "guess = %s; certainty = %.4f" % (r, classifications.certainty(r))
    else:
        score_files(args, c.test)