使用Tesseract和Pyocr在Python中获取字体大小

使用Tesseract和Pyocr在Python中获取字体大小,python,tesseract,font-size,python-tesseract,Python,Tesseract,Font Size,Python Tesseract,是否可以使用pyocr或Tesseract从图像中获取字体大小? 下面是我的代码 tools = pyocr.get_available_tools() tool = tools[0] txt = tool.image_to_string( Imagee.open(io.BytesIO(req_image)), lang=lang, builder=pyocr.builders.TextBuilder() ) 在这里,我使用函数image\u to\u st

是否可以使用
pyocr
Tesseract
从图像中获取字体大小? 下面是我的代码

tools = pyocr.get_available_tools()
tool = tools[0]
txt = tool.image_to_string(
      Imagee.open(io.BytesIO(req_image)),
      lang=lang,
      builder=pyocr.builders.TextBuilder()
)
在这里,我使用函数
image\u to\u string
从图像中获取文本。现在,我的问题是,如果我也能得到我的文本的
字体大小
(数字)。

使用,在调用图像上的
识别
后,你可以得到一个
结果生成器
,你可以调用
WordFontAttributes
方法来获得你需要的信息。有关更多信息,请阅读该方法的文档

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()
示例输出:

{'bold': False,
 'font_id': 283,
 'font_name': u'Times_New_Roman',
 'italic': False,
 'monospace': False,
 'pointsize': 9,
 'serif': True,
 'smallcaps': False,
 'underlined': False}

尝试将您的示例代码修改为。很遗憾,这看起来不再有效:/