我试图在 python 中运行一个基本且非常简单的代码。
from PIL import Image
import pytesseract
im = Image.open("sample1.jpg")
text = pytesseract.image_to_string(im, lang = 'eng')
print(text)
这就是它的样子,我实际上已经通过安装程序为 windows 安装了 tesseract。我对 Python 非常陌生,我不确定如何进行?
这里的任何指导将是非常有帮助的。我已经尝试重新启动我的 Spyder 应用程序,但无济于事。
我看到步骤分散在不同的答案中。根据我最近在 Windows 上使用此 pytesseract 错误的经验,按顺序编写不同的步骤,以便更轻松地解决错误:
1。使用 Windows 安装程序安装 tesseract,网址为:https://github.com/UB-Mannheim/tesseract/wiki
2。请注意安装中的 tesseract 路径。此编辑时的默认安装路径为:C:\Users\USER\AppData\Local\Tesseract-OCR
。它可能会更改,因此请检查安装路径。
pip install pytesseract
4。在调用image_to_string
之前,在脚本中设置 tesseract 路径:
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\USER\AppData\Local\Tesseract-OCR\tesseract.exe'
首先你应该安装二进制:
在 Linux 上
sudo apt-get update
sudo apt-get install libleptonica-dev tesseract-ocr tesseract-ocr-dev libtesseract-dev python3-pil tesseract-ocr-eng tesseract-ocr-script-latn
在 Mac 上
brew install tesseract
在Windows上
从https://github.com/UB-Mannheim/tesseract/wiki下载二进制文件。然后将pytesseract.pytesseract.tesseract_cmd = 'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
添加到脚本中。
然后你应该使用 pip 安装 python 包:
pip install tesseract
pip install tesseract-ocr
参考:https://pypi.org/project/pytesseract/(安装部分)和https://tesseract-ocr.github.io/tessdoc/Installation.html
仅适用于 Windows
1-您需要在计算机上安装 Tesseract OCR。
从这里得到它。https://github.com/UB-Mannheim/tesseract/wiki
下载合适的版本。
2-将 Tesseract 路径添加到系统环境。即编辑系统变量。
3-Runpip install pytesseract
andpip install tesseract
4-每次将此行添加到您的 python 脚本
pytesseract.pytesseract.tesseract_cmd = 'C:/OCR/Tesseract-OCR/tesseract.exe' # your path may be different
5-运行代码。
此错误是因为您的计算机上未安装 tesseract。
如果您使用的是 Ubuntu,请使用以下命令安装 tesseract:
sudo apt-get install tesseract-ocr
对于 Mac:
brew install tesseract
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(88条)