【问题标题】:Pytesseract does not recognize numbers despite trying every -psm尽管尝试了每个 -psm,Pytesseract 都无法识别数字
【发布时间】:2020-05-05 11:57:35
【问题描述】:

我一直试图从this image 获取一些数字,但 pytesseract 只给我随机字母。我尝试了许多 -psm 选项,但似乎不起作用。这是我正在使用的代码:

from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open("Test.png"), config="--psm 6"))

我能做些什么让它更成功?

【问题讨论】:

  • Tesseract 不喜欢黑色背景上的浅色文本。在浅色背景上使用深色文本效果更好。我还注意到,如果图像裁剪得太紧并且字符靠近图像边缘,有时 Tesseract 会遇到困难。

标签: python python-3.x python-imaging-library python-tesseract


【解决方案1】:

试试这个代码。

import cv2
import pytesseract

img = cv2.imread("vuK1z.png", 0)
thresh = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV)[1]
custom_config = r'-l eng --oem 3 --psm 6 '
text = pytesseract.image_to_string(thresh, config=custom_config)
print(text)

结果

550,000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多