【发布时间】:2018-09-12 19:19:23
【问题描述】:
我需要从图像中获取文本,但在我的图像中它只有一个数字,它可能是 1-9 之间的任何数字,我需要获取该数字。我正在使用 pytesseract 来执行此操作,但在阅读时显示空文本。 下面是我的图片:
下面是我正在尝试的:
from PIL import Image, ImageEnhance, ImageFilter
import pytesseract
def getText(image):
image = Image.open(image)
image.show()
image = image.point(lambda x: 0 if x < 143 else 255) # To clean Image
# text = pytesseract.image_to_string(image).encode('utf-8').strip()
text = pytesseract.image_to_string(image)
return text
image1 = '/home/einfochips/Documents/Kroger_Automation_Framework/src/main/scripts/background.png'
txt1 = getText(image1)
print txt1, '_______________', type(txt1), len(txt1)
【问题讨论】:
-
使用 tesseract 读取已知字体中的单个数字完全是矫枉过正。使用模板匹配
-
也许您可以尝试调整图像大小。
-
@flamelite 我试过了,但还是没有。
-
@Sachhya 我也试过了,我猜是因为 tesseract 将单个字符视为图形组件。因此,您可以尝试使用其他 OCR 库,或者您可以尝试在这种情况下特别适用的替代方法,将单个字符重复到同一图像中,您将获得由多个字符组成的 OCR 输出,您可以从那里获得所需的输出。
-
@flamelite 感谢您抽出宝贵时间,现在我将选择其他选择。
标签: python image-processing python-imaging-library pytesser