Skip to content

Instantly share code, notes, and snippets.

@Szuuuken
Last active March 22, 2019 21:42
Show Gist options
  • Save Szuuuken/6896290f4c0d905553b359766c720593 to your computer and use it in GitHub Desktop.
Save Szuuuken/6896290f4c0d905553b359766c720593 to your computer and use it in GitHub Desktop.
identify the font of each symbol in an image
# pyhton lib https://github.com/sirfz/tesserocr
# based on the libs example 'Iterator over the classifier choices for a single symbol' - https://github.com/sirfz/tesserocr#iterator-over-the-classifier-choices-for-a-single-symbol
from tesserocr import PyTessBaseAPI, RIL, iterate_level
def get_font(image_path):
with PyTessBaseAPI() as api:
api.SetImageFile(image_path)
api.Recognize()
ri = api.GetIterator()
level = RIL.SYMBOL
for r in iterate_level(ri, level):
symbol = r.GetUTF8Text(level)
word_attributes = r.WordFontAttributes()
if symbol:
print u'symbol {}, font: {}'.format(symbol, word_attributes['font_name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment