运行 pytesseract 中的示例代码
Running the sample code in pytesseract
我是 运行ning python 2.6.6 并且想安装 pytesseract 包。提取和安装后,我可以从命令行调用 pytesseract。但是我想 运行 python 内的 tesseract。我有以下代码 (ocr.py):
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'),lang='fra'))
当我通过 python ocr.py 运行 代码时,我得到以下输出:
Traceback (most recent call last):
File "ocr.py", line 6, in <module>
print(pytesseract.image_to_string(Image.open('test.png')))
File "/pytesseract-0.1.6/build/lib/pytesseract/pytesseract.py", line 164, in image_to_string
raise TesseractError(status, errors)
pytesseract.TesseractError: (2, 'Usage: python tesseract.py [-l language] input_file')
test.png 和 test-european.jpg 在工作目录中。有人可以帮我 运行 宁这个代码吗?
我尝试了以下方法:
- 将tesseract_cmd调整为'pytesseract'
- 已安装 tesseract-ocr
感谢任何帮助,因为我现在已经尝试解决这个问题好几个小时了。
tesseract_cmd
应该指向命令行程序 tesseract
,而不是 pytesseract
.
例如在 Ubuntu 上,您可以使用以下方式安装程序:
sudo apt install tesseract-ocr
然后将变量设置为 tesseract
或 /usr/bin/tesseract
。
我是 运行ning python 2.6.6 并且想安装 pytesseract 包。提取和安装后,我可以从命令行调用 pytesseract。但是我想 运行 python 内的 tesseract。我有以下代码 (ocr.py):
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'),lang='fra'))
当我通过 python ocr.py 运行 代码时,我得到以下输出:
Traceback (most recent call last):
File "ocr.py", line 6, in <module>
print(pytesseract.image_to_string(Image.open('test.png')))
File "/pytesseract-0.1.6/build/lib/pytesseract/pytesseract.py", line 164, in image_to_string
raise TesseractError(status, errors)
pytesseract.TesseractError: (2, 'Usage: python tesseract.py [-l language] input_file')
test.png 和 test-european.jpg 在工作目录中。有人可以帮我 运行 宁这个代码吗? 我尝试了以下方法:
- 将tesseract_cmd调整为'pytesseract'
- 已安装 tesseract-ocr
感谢任何帮助,因为我现在已经尝试解决这个问题好几个小时了。
tesseract_cmd
应该指向命令行程序 tesseract
,而不是 pytesseract
.
例如在 Ubuntu 上,您可以使用以下方式安装程序:
sudo apt install tesseract-ocr
然后将变量设置为 tesseract
或 /usr/bin/tesseract
。