如何在 python 或命令 window 中获得 Tesseract 置信度?

How to get Tesseract confidence levels in python or command window?

我们如何在 windows 中使用 tesseract 3.05 获得图像 OCR 后的置信度?我正在使用子进程命令从 python 调用 tesseract:

retcode = subprocess.call("tesseract -l eng myImage.png txt -psm 6" , stdin=None, stdout=False, stderr=None, shell=False)

您可以使用 tsv output:

tesseract testing/eurotext.png testing/eurotext-eng -l eng tsv

置信度在最后一列。

这是您需要的包装器: https://pypi.python.org/pypi/tesserocr/2.0.0。还有大量的 python 包装器,但是这个库是最接近的包装器,几乎涵盖了所有 C++ API.

示例:

from PIL import Image
from tesserocr import PyTessBaseAPI

image = Image.open('/usr/src/tesseract/testing/phototest.tif')
with PyTessBaseAPI() as api:
    api.SetImage(image)
    boxes = api.GetComponentImages(RIL.TEXTLINE, True)
    print 'Found {} textline image components.'.format(len(boxes))
    for i, (im, box, _, _) in enumerate(boxes):
        # im is a PIL image object
        # box is a dict with x, y, w and h keys
        api.SetRectangle(box['x'], box['y'], box['w'], box['h'])
        ocrResult = api.GetUTF8Text()
        conf = api.MeanTextConf()
        print (u"Box[{0}]: x={x}, y={y}, w={w}, h={h}, "
               "confidence: {1}, text: {2}").format(i, conf, ocrResult, **box)

添加到 Stef 的回答中,这是一个示例命令,用于检查 'output.tsv' 文件中的置信度值。

tesseract Ancestry1.jpg 输出 --oem 1 -l eng tsv

这里'Ancestry1.jpg'是要输入tesseract的图片文件。 oem 1 用于在 4.0 中使用 LSTM。 置信度存储在 'output.tsv' 文件中

Tesseract 官方网页的 link 置信度:Tesseract Wiki