gpt4 book ai didi

python-tesseract - Pytesseract.TesseractError'用法:python pytesseract.py [-l lang] input_file

转载 作者:行者123 更新时间:2023-12-04 08:01:50 55 4
gpt4 key购买 nike

尝试将简单的测试图像打印到文本时出现以下错误。

我已经验证我具有Pillow(PIL 1.1.7),并尝试卸载并重新安装pytesseract。文件路径是正确的,因为如果更改它们,则会收到另一个错误消息,指出找不到该文件。

我的代码:

    from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd= r'C:\Users\bbrown2\AppData\Local\
Programs\Python\Python37\Scripts\pytesseract'

img = r'C:\Users\bbrown2\Desktop\test.png'

print(pytesseract.image_to_string(Image.open(img)))


我希望它能打印出图像中的文字,但我总是这样:

    Traceback (most recent call last):
File
"c:\Users\bbrown2\Desktop\PythonMaterials\python_test_tesseract.py", line
14, in <module>
print(pytesseract.image_to_string(Image.open(image)))
File "C:\Users\bbrown2\AppData\Local\Programs\Python\Python37\lib\site-
packages\pytesseract\pytesseract.py", line 309, in image_to_string
}[output_type]()
File "C:\Users\bbrown2\AppData\Local\Programs\Python\Python37\lib\site-
packages\pytesseract\pytesseract.py", line 308, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\bbrown2\AppData\Local\Programs\Python\Python37\lib\site-
packages\pytesseract\pytesseract.py", line 218, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\bbrown2\AppData\Local\Programs\Python\Python37\lib\site-
packages\pytesseract\pytesseract.py", line 194, in run_tesseract
raise TesseractError(status_code, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (2, 'Usage: python pytesseract.py
[-l lang] input_file')

最佳答案

问题是pytesseract只是命令行程序Tesseract的一个不错的Python包装器。
您应该将tesseract_cmd指向实际的Tesseract二进制文件,而不是pytesseract CLI实用程序。

因此,您需要安装Tesseract。 Windows builds可用。我选择了3.05版安装程序,默认情况下将其安装为C:\Program Files (x86)\Tesseract-OCR\tesseract。然后,我运行以下命令,它运行良好:

from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = (
r"C:\Program Files (x86)\Tesseract-OCR\tesseract"
)

img = r"C:\Users\cody\Desktop\ocrtest.png"

print(pytesseract.image_to_string(Image.open(img)))


测试输入:

enter image description here
结果:

The (quick) [brown] {fox} jumps!
Over the $43,456.78 <lazy> #90 dog
& duck/goose, as 12.5% of E-mail
from aspammer@website.com is spam.
Der ,,schnelle” braune Fuchs springt
fiber den faulen Hund. Le renard brun
«rapide» saute par-dessus le chien
paresseux. La volpe marrone rapida
salta sopra i] cane pigro. El zorro
marrén répido salta sobre el perro
perezoso. A raposa marrom répida
salta sobre 0 C50 preguicoso.

关于python-tesseract - Pytesseract.TesseractError'用法:python pytesseract.py [-l lang] input_file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54725151/

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