def testStrings(self):
     for s in ["woolly", "mammoth"]:
         image = fgen.cairo_render_gray(s, fontname="Georgia", size=32)
         image = 1.0 * (image < amax(image) / 2)
         fst = self.linerec.recognizeLine(image)
         result = fst.bestpath()
         assert self.sequal(result, s), "result = %s" % result
 def testAlignment(self):
     s = "woolly"
     image = fgen.cairo_render_gray(s, fontname="Georgia", size=32)
     image = 1.0 * (image < amax(image) / 2)
     lattice, rseg = self.linerec.recognizeLineSeg(image)
     lmodel = fstutils.make_line_fst([s])
     result = ocrolib.compute_alignment(lattice, rseg, lmodel)
     assert result.output == s
     assert "".join(result.output_l) == s
 def testAlignmentWithLigatures(self):
     s = "woolly"
     gt = u"w_oo_lly"
     image = fgen.cairo_render_gray(s, fontname="Georgia", size=32)
     image = 1.0 * (image < amax(image) / 2)
     lattice, rseg = self.linerec.recognizeLineSeg(image)
     lmodel = fstutils.make_line_fst([gt])
     result = ocrolib.compute_alignment(lattice, rseg, lmodel)
     assert "".join(result.output_l) == s
     assert result.output_t == gt
     assert result.output_l == [u'w', u'oo', u'l', u'l', u'y']
 def charimage(self, c):
     image = fgen.cairo_render_gray(c, fontname="Georgia", size=32)
     image = fgen.gauss_degrade(image)
     return image
 def testChars(self):
     for c in ["A", "N", "n"]:
         image = fgen.cairo_render_gray(c, fontname="Georgia", size=32)
         r = ocrolib.ocosts(self.model.coutputs(image))
         assert r[0][0] == c, r[:3]