5

我收到此错误:[WinError 2] The system cannot find the file specified,仅当我使用 pytesser 进行 OCR 时。这是我的代码片段。

from PIL import Image
from pytesseract import *
image = Image.open('pranav.jpg')
print (image_to_string(image))****

否则,当我使用 PIL 更改图像大小时,我不会收到此错误。

4

6 回答 6

10

您不必编辑任何 pytesseract 文件。您可以在代码中声明 Tesseract 安装的路径,如下所示:

import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
于 2016-01-31T06:45:27.723 回答
3

我得到了同样的错误。您必须从这里安装 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'

并将其更改为您的 pytesseract.exe 所在的位置,在我的情况下,该行如下所示:

# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'c:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

现在你的代码应该可以工作了。

于 2015-12-17T23:39:02.807 回答
0

在环境变量中添加 tesseract 路径。

至少我是这样解决的。

于 2017-08-07T09:04:07.210 回答
0
  1. 您可以从这里下载 tesseract: https ://github.com/UB-Mannheim/tesseract/wiki

    可以在此处下载最新的安装程序:tesseract-ocr-setup-3.05.01.exe 和 tesseract-ocr-setup-4.0.0-alpha.20180109.exe(实验性)。也有旧版本可用。

  2. 编辑您的 pytesseract.py 例如。C:\Users\USER\Anaconda3\Lib\site-packages\pytesseract.py

    如果 TESSERACT 不在您的路径中,或者名称不同,请更改此设置 tesseract_cmd = 'c:\Program Files (x86)\Tesseract-OCR\tesseract'

  3. 在 import pytesseract 之后在代码中添加以下语句

    pytesseract.pytesseract.tesseract_cmd = 'c:\Program Files (x86)\Tesseract-OCR\tesseract'

于 2018-01-28T16:20:20.740 回答
0

要完全摆脱错误,请执行以下任务:

  1. 下载 tesseract(32 位|64 位)
  2. 在您的系统中安装相同的内容并记下路径。
  3. 创建环境变量 {tesseract = "安装路径/tesseract.exe"}
  4. 重启内核
  5. 使用以下代码:
import pytesseract

pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/ tesseract.exe'

from PIL import Image
value=Image.open("C://Profile_tess.png")

text = pytesseract.image_to_string(value)    
print("text present in images:",text)
于 2019-09-11T19:29:01.427 回答
0

设置 tesseract_cmd、pytesseract.pytesseract.tesseract_cmd、TESSDATA_PREFIX 和 tessdata_dir_config 如下:

from PIL import Image
import pytesseract
tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
pytesseract.pytesseract.tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
TESSDATA_PREFIX= 'D:\Softwares\Tesseract-OCR'
tessdata_dir_config = '--tessdata-dir "D:\\Softwares\\Tesseract-OCR\\tessdata"'
print(pytesseract.image_to_string( Image.open('D:\\ImageProcessing\\f2.jpg'), lang='eng', config=tessdata_dir_config))
于 2018-02-02T09:56:37.727 回答