我收到此错误:[WinError 2]只有当我使用pytesser进行OCR时,系统才能找到指定的文件.这是我的代码片段.
from PIL import Image
from pytesseract import *
image = Image.open('pranav.jpg')
print (image_to_string(image))****
Run Code Online (Sandbox Code Playgroud)
否则,当我使用PIL更改图像大小时,我不会收到此错误.
小智 10
您不必编辑任何pytesseract文件.您可以在代码中声明Tesseract安装的路径,如下所示:
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的错误。您必须从这里安装tesseract: https://code.google.com/p/tesseract-ocr/downloads/detail ?name=tesseract-ocr-setup-3.02.02.exe&
然后你必须编辑 pytesseract.py 文件。就我而言,该文件位于以下文件夹中:
C:\Users\USERNAME\AppData\Roaming\Python34\site-packages\pytesseract\pytesseract.py
搜索以下行(对我来说是第 60 行):
# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'tesseract'
Run Code Online (Sandbox Code Playgroud)
并将其更改为 pytesseract.exe 所在的位置,在我的例子中,该行如下所示:
# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'c:\\Program Files (x86)\\Tesseract-OCR\\tesseract'
Run Code Online (Sandbox Code Playgroud)
现在你的代码应该可以工作了。