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

标签 python tesseract font-size python-tesseract

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

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_to_string 从图像中获取文本。现在,我的问题是,我的文本是否也可以获得 font-size(number)。

最佳答案

使用 tesserocr ,你可以在你的图像上调用Recognize后得到一个ResultIterator,你可以调用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}

关于python - 使用 Tesseract 和 Pyocr 在 Python 中获取字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39324626/

相关文章:

python - 按行分组时如何合并 pandas 数据框的字典

python - 如何在 django、uwsgi 和 nginx 设置中反射(reflect) python 的变化

java - JTextPane:如何设置字体大小

Android WebView 缩放字体大小

r - 如何在 R 的 bquote 中为主要情节设置粗体字体?

python - 记录handleError()未拦截异常

python - 多人游戏中的Pygame和socket : OverflowError

forms - 通过字段识别和光学字符识别 (OCR) 在预定义表格上进行手写数据输入自动化

linux - 如何在 Ubuntu/Linux 发行版中安装 Tesseract-OCR 3.03?

用于 Symbian 和 MeeGo 的 C++ OCR 库