为什么python tesseract为字母提供了错误的拼音框?

为什么python tesseract为字母提供了错误的拼音框?,python,tesseract,python-tesseract,Python,Tesseract,Python Tesseract,我在tesseract v4上使用python tesseract包装器(tesserocr)。我在一个简单的“HELLO WORLD”黑白图像上运行了一些示例代码,但是尽管字母被正确识别,但我得到了错误的边界框,看到了原始图像上叠加的结果 下面是基于的代码。知道如何得到正确的BBox吗?谢谢大家! import cv2 import json from PIL import Image from tesserocr import PyTessBaseAPI, RIL img = cv2.i

我在tesseract v4上使用python tesseract包装器(tesserocr)。我在一个简单的“HELLO WORLD”黑白图像上运行了一些示例代码,但是尽管字母被正确识别,但我得到了错误的边界框,看到了原始图像上叠加的结果

下面是基于的代码。知道如何得到正确的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]]
原来“brew安装tesseract--HEAD”给我带来了损坏的train文件

wget -O "eng.traineddata" "https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata"
我还需要切换到仅Tesseract发动机模式:

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