我正在使用 Tesseract 和 Python 从图像构建字符标识符。
这是我的代码:
from PIL import Image
import pytesseract as pyt
image_file = 'location'
im = Image.open(image_file)
text = pyt.image_to_string(image_file)
print (text)
执行此程序时出现以下错误:
类型错误:不支持的图像对象
谁能解决这个问题?
原文由 Srikanth 发布,翻译遵循 CC BY-SA 4.0 许可协议
首先,记得添加行
其中
C:/Program Files/Tesseract-OCR/tesseract.exe
是安装 tesseract 的位置。你已经说明图片文件是字符串了,没问题,但是你没有添加图片的扩展名!例如,您会写成image_file = 'location.png'
。扩展名 jpeg,或您的图像所持有的任何其他格式。然后,不要写text = pyt.image_to_string(image_file)
,而是写text = pyt.image_to_string(img)
因为它是您正在解析的图像而不是字符串。其余代码没问题。注意: 您可能需要指定图像的确切位置;例如 ‘C:/Users/Dismas/Desktop/opencv-python/image_text.png’
但如果您仍然遇到同样的问题,您可以使用链接 如何安装 tesseract OCR 。我按原样按照其中的步骤进行操作。我遇到了和你类似的问题,但现在我已经解决了。 下面的图片可能是更好理解 截图 的好来源