Last active
March 22, 2019 21:42
-
-
Save Szuuuken/6896290f4c0d905553b359766c720593 to your computer and use it in GitHub Desktop.
identify the font of each symbol in an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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