Pytesseract在windows操作系统上不工作。子流程.py失踪了?

2024-04-28 14:41:11 发布

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

我试图让tesseract ocr识别图像上的字符串。我在windows操作系统的pc上使用python。我已经为tesseract OCR安装了python包装器,即pytesseract with pip install。我收到以下错误消息:

runfile('C:/Users/rlc/Desktop/tesseract_test.py', wdir='C:/Users/rlc/Desktop')
Traceback (most recent call last):
  File "<ipython-input- 1-5f5eff4c4064>", line 1, in <module>
    runfile('C:/Users/rlc/Desktop/tesseract_test.py', wdir='C:/Users/rlc/Desktop')
  File "C:\Users\rlc\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
    execfile(filename, namespace)
  File "C:\Users\rlc\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "C:/Users/rlc/Desktop/tesseract_test.py", line 12, in <module>
    pytesseract.image_to_string(Image.open('example_02.png'))
  File "C:\Users\rlc\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
    config=config)
  File "C:\Users\rlc\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "C:\Users\rlc\Anaconda2\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Users\rlc\Anaconda2\lib\subprocess.py", line 959, in _execute_child
    startupinfo)
    WindowsError: [Error 2] Den angivne fil blev ikke fundet.

似乎找不到文件子流程.py. 在

有没有让tesseract ocr在windows os pc上运行的解决方案、好主意或教程?非常感谢你的帮助。在


Tags: inpytestlibpackageslinesiteusers
2条回答

开始扫描图像时,请这样使用:

import pytesseract
pytesseract.pytesseract.tesseract_cmd=r'C:\Tesseract-OCR\tesseract.exe'

text = str(pytesseract.image_to_string(filename))
print(text)

注意:不要使用“C:\Tesseract OCR”的实际路径\tesseract.exe文件在你的电脑里

以下是tesseract最新版本的链接:

32位版本

访问:https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w32-setup-v5.0.0-alpha.20191030.exe

64位版本

访问:https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-v5.0.0-alpha.20191030.exe

明白了吗子流程.py实际上包括在水蟒2和Python3中。错误的原因是tesseract所在的路径没有作为环境路径变量添加到Windows中。在

使pytesseract在windows上运行的步骤。在

  1. https://www.continuum.io/downloads安装Python2或Python3
  2. http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe安装tesseract for windows
  3. 将tesseract目录作为PATH环境变量添加到windows中。在
  4. 安装pytesseract,例如

    pip安装pytesseract

还有。。在

    import pytesseract
    from PIL import Image
    image = Image.open('example_02.png')
    code = pytesseract.image_to_string(image)
    print code

你好。在

相关问题 更多 >