【发布时间】:2017-09-01 17:54:32
【问题描述】:
我正在尝试对 pytesseract 使用 0 的 psm,但出现错误。我的代码是:
import pytesseract
from PIL import Image
img = Image.open('pathToImage')
pytesseract.image_to_string(img, config='-psm 0')
出现的错误是
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 126, in image_to_string
f = open(output_file_name, 'rb')
IOError: [Errno 2] No such file or directory:
'/var/folders/m8/pkg0ppx11m19hwn71cft06jw0000gp/T/tess_uIaw2D.txt'
当我进入“/var/folders/m8/pkg0ppx11m19hwn71cft06jw0000gp/T”时,有一个名为 tess_uIaw2D.osd 的文件似乎包含我正在寻找的输出信息。似乎 tesseract 正在将文件保存为 .osd,然后查找该文件但扩展名为 .txt。当我使用 --psm 0 通过命令行运行 tesseract 时,它将输出文件保存为 .osd 而不是 .txt。
pytesseract 的 image_to_string() 通过将输出文件保存在某处然后自动读取该输出文件来工作是否正确?有什么方法可以设置 tesseract 将文件保存为 .txt,或者将其设置为查找 .osd 文件?当我不设置 psm 时,我只运行 image_to_string() 函数没有问题。
【问题讨论】:
标签: python tesseract file-extension python-tesseract