为什么通过python执行tesseract OCR会冻结?

2024-10-02 08:20:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经下载了Tesseract OCR for Windows,我可以通过以下方式轻松地将图像转换为文本:

C:\>"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" screenshot22.png output -l spa

它工作得很好,只需要一秒钟的时间。在

这是它的版本:

^{pr2}$

因此,我下载了pytesseract python库:

C:\Users\ghade\Desktop>pip3 install pytesseract --no-cache-dir
Collecting pytesseract
  Downloading https://files.pythonhosted.org/packages/f9/4d/0cc26dbb2298080ed0f1ca848c06a1b68ab041e809f3583fe8642ee228cc/pytesseract-0.2.5.tar.gz (169kB)
    100% |████████████████████████████████| 174kB 817kB/s
Requirement already satisfied: Pillow in c:\users\ghade\appdata\local\programs\python\python37-32\lib\site-packages (from pytesseract) (5.3.0)
Installing collected packages: pytesseract
  Running setup.py install for pytesseract ... done
Successfully installed pytesseract-0.2.5

所以我可以用python这样执行:

import pytesseract
from PIL import Image

# If I comment this line, it does not works
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'

print(pytesseract.image_to_string(Image.open('screenshot22.png'), lang='spa'))

相同的图像和相同的参数。但它被卡在最后一行,而且永远不会返回任何内容。我错过了什么?你还有其他选择吗?在


Tags: 图像forpngpackagesfilesprogramexex86

热门问题