为什么python tesseract给字母错误的绑定框?

时间:2018-08-19 13:30:49

标签: python tesseract python-tesseract

我在tesseract v4上使用python tesseract包装器(tesserocr)。我正在一个简单的“ HELLO WORLD”黑白图像上运行一些示例代码,但是尽管字母可以正确识别,但是边界框却错了,请参见原始图像上覆盖了结果

https://github.com/robbyrussell/oh-my-zsh.git

这是基于enter image description here的代码。任何想法如何获得正确的bbox?谢谢!

import cv2
import json
from PIL import Image
from tesserocr import PyTessBaseAPI, RIL

img = cv2.imread('helloworld.jpg')
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
pillowImg = Image.fromarray(gray_img)
with PyTessBaseAPI() as api:
    api.SetImage(pillowImg)
    api.Recognize()
    ri = api.GetIterator()
    level = RIL.SYMBOL
    for r in tesserocr.iterate_level(ri, level):
        bbox = r.BoundingBoxInternal(level)
        symbol = r.GetUTF8Text(level)
        conf = r.Confidence(level)
        print(json.dumps([symbol, conf, bbox]))

这是输出:

["H", 99.57249450683594, [185, 361, 234, 427]]
["E", 99.54733276367188, [251, 361, 292, 427]]
["L", 99.50984954833984, [311, 361, 353, 427]]
["L", 99.4959716796875, [362, 361, 404, 427]]
["O", 99.55082702636719, [420, 359, 472, 428]]
["W", 99.52144622802734, [529, 361, 589, 427]]
["O", 99.55513763427734, [589, 361, 611, 427]]
["R", 99.56971740722656, [647, 359, 721, 428]]
["L", 99.55563354492188, [756, 361, 779, 427]]
["D", 99.56954956054688, [807, 361, 861, 427]]

1 个答案:

答案 0 :(得分:0)

事实证明,“酿造tesseract --HEAD”给我带来了损坏的火车文件!

wget -O "eng.traineddata" "https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata"

我还需要切换到仅Tesseract引擎模式:

with PyTessBaseAPI(oem=OEM.TESSERACT_ONLY) as api:

就是这样