def show_shear(sent): she = 7 img = ochre.get_sentence(sent) img_ = ochre.generators.shear(ochre.get_sentence(sent), shearing=she) img = np.concatenate((img, img_), axis=1) img_ = ochre.generators.shear(ochre.get_sentence(sent), shearing=-she) img = np.concatenate((img, img_), axis=1) plt.imshow(img) plt.show()
def show_shift(sent): shi = 2 # number of shifts each direction img = ochre.get_sentence(sent) for i in range(shi * 2): img_ = ochre.generators.shift(ochre.get_sentence(sent), 2 * (i - shi), 0) img = np.concatenate((img, img_), axis=1) for i in range(shi * 2): img_ = ochre.generators.shift(ochre.get_sentence(sent), 0, 2 * (i - shi)) img = np.concatenate((img, img_), axis=1) plt.imshow(img) plt.show()
def main(sentence, collection=True): print(sentence) box = lambda idx: (0, idx * 14, 14, (idx + 1) * 14) sentence_img = ochre.get_sentence(sentence) letters = sorted(set(sentence.replace(" ", ""))) if collection: ts = { c: list(ochre.collection.collection(ochre.get_letter(c))) for c in letters } else: ts = {c: [ochre.get_letter(c)] for c in letters} nn = ochre.training.train(ts) prediction = [ ochre.training.predict(nn, sentence_img, box=box(idx)) for idx in range(len(sentence)) ] print("".join(prediction)) for idx, c in enumerate(sentence): if c == " ": print(f"Skipping space at idx={idx}") continue letter = ochre.training.predict(nn, sentence_img, box=box(idx)) cor = "ok" if letter == c else "fail" print(f"{letter} == {c} {cor}")
def test_sentence(): box = lambda idx: (0, idx * 14, 14, (idx + 1) * 14) sentence = "my first word".lower() sentence_img = ochre.get_sentence(sentence) letters = sorted(set(sentence.replace(" ", ""))) nn = _get_nn(letters) for idx, c in enumerate(sentence): if c == " ": print(f"Skipping space at idx={idx}") continue letter = ochre.training.predict(nn, sentence_img, box=box(idx)) assert letter == c
def vis_sentence(sent): coll = list( ochre.collection.collection( ochre.get_sentence(sent, serif=os.getenv("SERIF")))) return coll