OSError:[Errno 2]没有使用pytess的文件或目录

2024-06-01 05:37:43 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的问题,我想用pytesser来获取图片的内容。我的操作系统是Mac OS 10.11,我已经安装了PIL、pytesser、tesseract ocr引擎和其他支持库,比如libpng等等。但当我运行代码时,如下所示,会发生错误。

from pytesser import *
import os
image = Image.open('/Users/Grant/Desktop/1.png')
text = image_to_string(image)
print text

接下来是错误消息

Traceback (most recent call last):
File "/Users/Grant/Documents/workspace/image_test/image_test.py",    line 10, in <module>
text = image_to_string(im)
File   "/Users/Grant/Documents/workspace/image_test/pytesser/pytesser.py", line   30, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "/Users/Grant/Documents/workspace/image_test/pytesser/pytesser.py", line 21, in call_tesseract
retcode = subprocess.call(args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/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

另外,tesseract ocr引擎在我的Mac上运行良好,我可以在终端运行并得到结果。下面是测试图片结果。 tesseract result

有人能帮我解决这个问题吗?


Tags: totextinpytestimagestringline
3条回答

我也遇到了同样的问题,但我成功地将图像转换为字符串。 使用apt-get应该可以做到:

sudo apt-get install tesseract-ocr

如果不能在python脚本中使用它,请执行以下操作:

from os import system

system("tesseract -l eng /image.png text.txt")

幸运的是,我解决了这个问题。

首先,我运行命令

pip install pytesseract

安装软件包。

但我得到的错误消息是“没有使用pytesser的此类文件或目录”。

然后我读了这个链接:image_to_string doesn't work in Mac 所以,只需运行以下脚本:

brew link libtiff 
brew link libpng 
brew link jpeg
brew install tesseract

为我工作~

打开文件pytesseract.py

我的在/Users/yourUser/.virtualenvs/cv/lib/python2.7/site-packages/pytesseract/pytesseract.py

tesseract_cmd = 'tesseract'更改为tesseract_cmd = '/usr/local/bin/tesseract'

相关问题 更多 >