使用Tesseract和Pyocr在Python中获取字体大小 [英] get Font Size in Python with Tesseract and Pyocr

查看:249
本文介绍了使用Tesseract和Pyocr在Python中获取字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to get font size from an image using pyocr or Tesseract? Below is my code.

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(数字)我的文本.

Here i get text from image using function image_to_string . And now, my question is, if i can get font-size(number) too of my text.

推荐答案

使用 tesserocr ,您可以获得在图像上调用Recognize之后,单击ResultIterator,可以调用WordFontAttributes方法来获取所需的信息.阅读该方法的文档以获取更多信息.

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()

示例输出:

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

这篇关于使用Tesseract和Pyocr在Python中获取字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆