gpt4 book ai didi

python - 图片中的文字是否加粗?

转载 作者:行者123 更新时间:2023-12-03 17:31:03 24 4
gpt4 key购买 nike

我一直在用 Tesseract OCR 试验 latley。我能够在图像中找到字符,但我无法仅找到图像中的粗体字符(知道文档图像中的字符是否为粗体)。我在 Tesseract API 的另一个问题 ( Can I use OCR to detect font style (bold, italic)? ) 中看到了 WordFontAttributes() 函数,但我无法在 Python 中实现它。

最佳答案

在安装 tesseract 3.05 之前(第 4 版不支持 WordFontAttributes)

from tesserocr import PyTessBaseAPI, RIL, iterate_level


def get_words_info(image_path, tessdata_path):
"""
get path to image and path to tessdata and return dict with info about each word
"""
# api = PyTessBaseAPI(path=tessdata_path)
with PyTessBaseAPI(path=tessdata_path) as api:
api.SetImageFile(image_path)
api.Recognize()
iter = api.GetIterator()
level = RIL.WORD

result = []

for r in iterate_level(iter, level):
element = r.GetUTF8Text(level)
word_attributes = r.WordFontAttributes()
base_line = r.BoundingBox(level)

if element:
word_attributes['word'] = element
word_attributes['position'] = base_line

result.append(word_attributes)

return result

关于python - 图片中的文字是否加粗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54009125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com