image_to_string 在 Mac 上无法工作。

7

我正在尝试在Mac Maverick上跟随pytesser的这个示例(链接)。


>>> from pytesser import *
>>> im = Image.open('phototest.tif')
>>> text = image_to_string(im)

但是,在最后一行我遇到了这个错误信息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pytesser.py", line 31, in image_to_string
    call_tesseract(scratch_image_name, scratch_text_name_root)
  File "pytesser.py", line 21, in call_tesseract
    proc = subprocess.Popen(args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

但是,我不明白我应该做什么。文件 phototest 在我运行脚本的同一文件夹中。如何解决这个问题?
更新:
当我尝试时:
brew install tesseract

I get this error:

Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
Error: You must `brew link libtiff libpng jpeg' before tesseract can be installed

明白了。但我能做到这个吗? - Filipe Ferminiano
我相信这是可行的,但我不知道具体细节:这个问题应该标记为tessact用户。 - Luis
好的,已经标记了Tesseract主题。 - Filipe Ferminiano
你可以使用 brew install tesseract 命令安装 Tesseract。 - Andrea de Marco
我尝试了,但是出现了错误信息。我已经更新了我的问题并附上了错误信息,请看一下。 - Filipe Ferminiano
显示剩余3条评论
1个回答

9

我其实也遇到了和你一样的错误,正是因为这个才找到了这篇文章。而且你给出了解决方案,正好帮助了我!

我看到的错误信息是:

ryan.davis$ python tesseract.py
Traceback (most recent call last):
  File "tesseract.py", line 52, in <module>
    print (image_to_string(big))
  File "/usr/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
    config=config)
  File "/usr/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

想知道我是如何解决这个问题的吗?就是你尝试过的方法:brew install tesseract。我已经安装了tesseract python库,但没有在系统级别上安装。所以这解决了我的问题。你的问题呢?
我认为你可能被这个干扰了:

警告:看起来你安装了MacPorts或Fink。使用其他软件包管理器安装的软件会导致Homebrew出现已知问题。如果某个公式无法构建,请卸载MacPorts/Fink并重试。

而没有注意到brew的回应已经提供了答案:

在安装tesseract之前,必须先链接libtiff libpng jpeg。

所以执行以下操作:
brew link libtiff 
brew link libpng 
brew link jpeg

然后:

brew install tesseract

最后:

:)

它对我有效,谢谢!Mac OS High Sierra,Python 3 =) - Antonio Cachuan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接