Sri*_*nth 5 python python-imaging-library python-3.x python-tesseract
我正在使用 Tesseract 和 Python 从图像构建字符标识符。
\n\n这是我的代码:
\n\nfrom PIL import Image\nimport pytesseract as pyt\n \xc2\xa0\nimage_file = \'location\'\nim = Image.open(image_file)\ntext = pyt.image_to_string(image_file)\nprint (text)\nRun Code Online (Sandbox Code Playgroud)\n\n我在执行该程序时收到以下错误:
\n\n\n\n\n类型错误:不支持的图像对象
\n
有人能解决这个问题吗?
\n首先,记得添加一行
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
Run Code Online (Sandbox Code Playgroud)
where
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。我按照其中的步骤进行操作。我也遇到了和你类似的问题,不过现在已经解决了。 下图可能是更好地理解 屏幕截图的一个很好的来源