问题描述
首先我做了这里提到的一切pytesseract-no such file or directory错误
First of all I did everything mentioned here pytesseract-no such file or directory error
还是不行.现在我正在使用带有以下代码的 Pycharm IDE:
Still doesn't work. Now I'm using Pycharm IDE with following code:
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 一起使用时找不到图像.
I don't get it. Why I am able to use tesseract in shell but not in python. And in python I can open same image but when used with tesseract Image can't be found.
您可以在下面看到错误输出.
Below you can see the error output.
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
推荐答案
我解决了自己的问题.
im = Image.open('test.png')
print pytesseract.image_to_string(im)
目前尚不清楚为什么它在传递引用时有效,但在我尝试在参数内打开图像时却不直接.
It's still unclear why it works when a reference is passed but not directly when I try to open image inside the parameter.
这篇关于Pytesseract No such file or directory 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!