get Font Size in Python with Tesseract and Pyocr

空扰寡人 提交于 2019-12-04 13:13:46

Using tesserocr, you can get a ResultIterator after calling Recognize on your image, for which you can call the WordFontAttributes method to get the information you need. Read the method's documentation for more info.

import io
import tesserocr
from PIL import Image

with tesserocr.PyTessBaseAPI() as api:
    image = Image.open(io.BytesIO(req_image))
    api.SetImage(image)
    api.Recognize()  # required to get result from the next line
    iterator = api.GetIterator()
    print iterator.WordFontAttributes()

Example output:

{'bold': False,
 'font_id': 283,
 'font_name': u'Times_New_Roman',
 'italic': False,
 'monospace': False,
 'pointsize': 9,
 'serif': True,
 'smallcaps': False,
 'underlined': False}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!