python 的 OCR 小图像

OCR small image with python

我需要用 python 2.7 识别小图像,包含价格。

如您所见,图像非常小,但包含一些值。

我的目标是解码为:654.10

我尝试使用 tesseract,但我没有运气。

import pytesseract
print(pytesseract.image_to_string(Image.open('example.png') , lang='eng', boxes=False,config='--psm 10 --eom 3 -c tessedit_char_whitelist=€0123456789'))

我得到:

€553 1

我尝试使用在线转换器并且工作得很好 (https://convertio.co/it/ocr/),所以我认为这是可能的。

有人有更好的主意吗?

谢谢

(抱歉我的英语不好)

更新:

我尝试在没有任何运气的情况下对图像进行阈值处理......再次......

import cv2
img = cv2.imread('cropped.png')
grayscaled = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
retval, threshold2 = cv2.threshold(grayscaled,125,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imwrite('threshold.jpeg',threshold2)
print(pytesseract.image_to_string(Image.open('threshold.jpeg') , lang='eng', boxes=False,config='--psm 10 --eom 3 -c tessedit_char_whitelist=0123456789'))

输出:553 0 图像输出:

ps。我裁剪了原始图像,删除了 € 符号...但仍然出现错误。

谢谢

我通过调整图像大小然后应用阈值解决了我的问题。

此代码将增加图像的维度:

    basewidth = 300
    img = Image.open(saved_location)
    wpercent = (basewidth/float(img.size[0]))
    hsize = int((float(img.size[1])*float(wpercent)))
    img = img.resize((basewidth,hsize), Image.ANTIALIAS)
    img.save(saved_location)

感谢评论中的用户post。