gpt4 book ai didi

python - 在Python脚本中使用光学字符识别

转载 作者:太空宇宙 更新时间:2023-11-03 14:01:52 24 4
gpt4 key购买 nike

我想完成看似简单的任务,即运行一个 python 脚本,该脚本使用 OCR 为我提供图像中的一串文本。我的代码:

from PIL import Image
from pytesseract import *

image_file = 'IMG_9296'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text

但是,我在第二行遇到了麻烦。我在 Mac OS X 上成功安装了 Pillow、PIL 和 pytesseract(运行 Python 2.7、Pillow-5.0.0 pytesseract-0.2.0)。但我收到此错误:

Traceback (most recent call last):
File "./HQcode2.py", line 2, in <module>
from pytesseract import *
File "/Library/Python/2.7/site-packages/pytesseract/__init__.py", line
1, in <module>
from .pytesseract import (
File "/Library/Python/2.7/site-packages/pytesseract/pytesseract.py",
line 9, in <module>
import Image
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 27, in
<module>
from . import VERSION, PILLOW_VERSION, _plugins
ValueError: Attempted relative import in non-package

我已查找此错误,但尚未发现任何对我的情况有帮助的信息。这里似乎出了什么问题,我该如何解决它?

最佳答案

您能确认您也安装了 tesseract 吗? (https://github.com/madmaze/pytesseract#installation)

基于此问题:https://github.com/madmaze/pytesseract/issues/58 ,该包的作者似乎表明您的问题是缺少依赖项。

关于python - 在Python脚本中使用光学字符识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49182395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com