2016-06-29 34 views
5

首先,我所做的一切这里提到pytesseract-no such file or directory errorPytesseract没有这样的文件或目录错误

还不行。现在,我使用Pycharm IDE与下面的代码:

from PIL import Image 
import pytesseract 
import subprocess 

im = Image.open('test.png') 
im.show() 
subprocess.call(['tesseract','test.png','out']) 
print pytesseract.image_to_string(Image.open('test.png')) 
  • im.show()成功打开图像。
  • subprocess.call()with tesseract test.png out也从图像中提取文本 ..
  • 但pytesseract.image_to_string()失败。

我不明白。为什么我能够在shell中使用tesseract,但不能在python中使用。在python中,我可以打开相同的图像,但与tesseract一起使用时无法找到图像。

您可以在下面看到错误输出。

File "/home/hamza-c/Schreibtisch/Android/JioShare/orc.py", line 7, in <module> 
    print pytesseract.image_to_string(Image.open('/home/hamza-c/Schreibtisch/Android/JioShare/test.png')) 
    File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 162, in image_to_string 
    config=config) 
    File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 95, in run_tesseract 
    stderr=subprocess.PIPE) 
    File "/usr/lib/python2.7/subprocess.py", line 711, in __init__ 
    errread, errwrite) 
    File "/usr/lib/python2.7/subprocess.py", line 1340, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 
+0

我有同样的问题,并找到解决方案[这里](https://stackoverflow.com/questions/28741563/pytesseract-no-such-file-or-directory-error) –

回答

-2

我解决了我自己的问题。

im = Image.open('test.png') 
print pytesseract.image_to_string(im) 

目前还不清楚为什么它的工作原理,当一个引用传递而不是直接当我尝试打开参数内的图像。

5

我测试了你在你的问题中提到的代码。它工作正常。我面临着同样的错误

没有这样的文件或目录中找到

问题是含有“tesseract.exe”不添加到环境变量中的目录。您应该能够在命令提示符下运行命令'tesseract'。

如果没有安装正方体你可以从tesseract 1下载:https://github.com/tesseract-ocr/tesseract/wiki和Windows使用可用第三方的安装here

0

也许你需要安装正方体,如果你的操作系统是CentOS的,请输入

yum install tesseract 
相关问题