【发布时间】:2018-10-25 17:26:19
【问题描述】:
我已经下载了适用于 Windows 的 Tesseract OCR,我可以通过这种方式轻松地将图像转换为文本:
C:\>"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" screenshot22.png output -l spa
它工作正常,它的执行只需要一秒钟。
这是它的版本:
C:\>"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" -v
tesseract 3.05.02
leptonica-1.75.3
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.2.0
因此,我已经下载了 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'))
相同的图像和相同的参数。但它卡在最后一行,它永远不会返回任何东西。我错过了什么?你有其他选择吗?
【问题讨论】:
-
如果删除
pytesseract.pytesseract.tesseract_cmd = ...行会怎样?或者如果你在命令行上使用C:\Program Files (x86)\Tesseract-OCR\tesseract.exe? -
我已经更新了针对您的建议的问题。谢谢!
标签: python pip ocr tesseract python-tesseract