我需要从图像中获取文本,但在我的图像中它只有一个数字,可以是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)
您需要设置psm值。默认值是模式0(我相信)。
这对我有用
text = pytesseract.image_to_string(Image.open(filename),config=' psm 10')
相关问题 更多 >
编程相关推荐