gpt4 book ai didi

python - 将图像转换为字符串时出现pytesseract错误

转载 作者:太空宇宙 更新时间:2023-11-04 05:09:17 26 4
gpt4 key购买 nike

我不断收到以下代码的错误:

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter

im = Image.open("book.jpg") # the second one
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
text = pytesseract.image_to_string(im)
print text

错误是:

File "demo2.py", line 9, in <module>
text = pytesseract.image_to_string(im)
File "/home/vagrant/src/env/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
config=config)
File "/home/vagrant/src/env/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 94, 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 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

我不确定这是安装问题还是其他原因。我阅读了 OSError: [Errno 2] No such file or directory using pytesser 的答案,但他们没有帮助我。

最佳答案

我有同样的问题,但我设法将图像转换为字符串。使用 apt-get 应该可以解决问题:

sudo apt-get install tesseract-ocr

如果你不能在 python 脚本中使用它,就这样做:

from os import system

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

关于python - 将图像转换为字符串时出现pytesseract错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43487972/

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