pytesseract使用tesseract 4.0数字仅不起作用

Cur*_*rge 6 python tesseract

有人试图获取仅在python中调用tesseract 4.0的最新版本的数字吗?

下面的代码在3.05中有效,但在4.0中仍返回字符,我尝试删除所有配置文件,但数字文件仍然无效。任何帮助都会很棒:

im是日期的图像,黑色文本白色背景:

import pytesseract
im =  imageOfDate
im = pytesseract.image_to_string(im, config='outputbase digits')
print(im)
Run Code Online (Sandbox Code Playgroud)

Rob*_*ris 11

在 pytesseract 中使用 tessedit_char_whitelist 标志对我不起作用。但是,一种解决方法是使用一个有效的标志,即 config='digits':

import pytesseract
text = pytesseract.image_to_string(pixels, config='digits')
Run Code Online (Sandbox Code Playgroud)

其中像素是图像的 numpy 数组(PIL 图像也应该有效)。这应该会强制您的 pytesseract 只返回数字。现在,要自定义它返回的内容,请找到您的数字配置文件,在 Windows 上,我的位于此处:

C:\Program Files (x86)\Tesseract-OCR\tessdata\configs

打开数字文件并添加您想要的任何字符。保存并运行 pytesseract 后,它应该只返回那些自定义字符。


the*_*ere 8

您可以在tessedit_char_whitelist下方将数字指定为config option

ocr_result = pytesseract.image_to_string(image, lang='eng', boxes=False, \
           config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
Run Code Online (Sandbox Code Playgroud)

希望能有所帮助。

  • 该解决方案不适用于tesseract 4.0+。在GitHub上有一个与此相关的未解决问题:https://github.com/tesseract-ocr/tesseract/issues/751。 (3认同)

小智 5

您可以将下面的数字指定tessedit_char_whitelist为配置选项。

ocr_result = pytesseract.image_to_string(image, lang='eng',config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
Run Code Online (Sandbox Code Playgroud)