如何在python或command窗口中获取Tesseract置信级别?

2024-06-12 02:05:17 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在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)


Tags: 图像命令nonefalsepng进程windowscall
3条回答

这是您需要的包装: 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)

您可以使用tsv output。置信水平在最后一列。

除了Stef的回答之外,这里还有一个示例命令,用于检查“output.tsv”文件中的置信值。

tesseract祖先1.jpg输出——oem 1-l eng tsv

这里,'祖先1.jpg'是要输入到tesseract的图像文件。 oem 1用于在4.0中使用LSTM。 置信度存储在“output.tsv”文件中

信任级别的官方Tesseract网页链接:Tesseract Wiki

相关问题 更多 >