从图像中读取文本

时间:2016-08-30 02:56:52

标签: python image-processing pytesser

有关将这些图像转换为文字的建议吗?我使用pytesseract,除了这个以外,它在大多数情况下都能很好地工作。理想情况下,我会准确地阅读这些数字。最糟糕的情况我可以尝试使用PIL来确定' /'左边的数字。是零。从左边开始,找到第一个白色像素,然后

enter image description here enter image description here

def ConvertPPTextToReadableNumbers(text):
    text = RemoveNonASCIICharacters(text)
    text = text.replace("I]", "0")
    text = text.replace("|]", "0")
    text = text.replace("l]", "0")
    text = text.replace("B", "8")
    text = text.replace("D", "0")
    text = text.replace("S", "5")
    text = text.replace(".I'", "/")
    text = text.replace(".I", "/")
    text = text.replace("I'", "/")
    text = text.replace("J", "/")
    return text

中间的斜线导致问题。我也尝试过使用PIL' .paste'在图像周围添加大量额外的黑色。我可能会尝试其他一些PIL技巧,但除非必须,否则我宁愿不去那条路。

我尝试使用config =' -psm 10'但我的8岁以及#34;:"有时,和其他时间的随机字符。我的0都没有成功。

参考:pytesseract don't work with one digit image用于-psm 10

_____________ EDIT _______________ 其他样本:

enter image description here 1BJ2I]

enter image description here DIS

enter image description here 10.我' 10

enter image description here 20.I20

所以我正在做一些似乎现在正在工作的巫术转换。但看起来很容易出错:

ConvertPPTextToReadableNumbers return text =  18/20
ConvertPPTextToReadableNumbers return text =  0/5
ConvertPPTextToReadableNumbers return text =  10/10
ConvertPPTextToReadableNumbers return text =  20/20

最终产生:

Operating System

2 个答案:

答案 0 :(得分:4)

一般来说,大多数OCR工具(如Tesseract)都经过调整,可以处理印刷文本的高分辨率扫描。它们在低分辨率或像素化图像上表现不佳。

这里有两种可能的方法:

  1. 如果您的图片的字体,背景和布局完全可以预测,那么您根本不需要Tesseract;这只会使问题复杂化。构建一个代表您需要识别的每个角色的图像库,并check whether parts of the image are equal to the reference image

  2. 如果这不是一个选项,或者看起来太难,您可以使用the hq*x algorithms中的一个来升级像素化图像。添加的细节可能足以让Tesseract可靠地识别字符。

答案 1 :(得分:3)

如果仍然有人迷迷糊糊...问题是字母是白色而背景是黑色...在我的应用程序中,切换了(白色背景黑色字母)后,我得到了大约98%的准确度为此使用了cv2