0

我正在尝试通过基于 Python 2.7 的 Anaconda 使 tesseract OCR 工作。在对流程提出各种更改后,这是这里编写的最终代码。

> import os 

> from PIL import * 

> from PIL import Image 

> from tesseract import *                #different : quantum simulations
> 
> import pytesseract
> 
> print os.getcwd() 

> im = Image.open('D:\File_conv\phototest.tif') #to be sure of path

> im.load() 

> print im
> text = pytesseract.image_to_string(im)       #Generates error
> import pytesseract
> print(pytesseract.image_to_string(Image.open(
> 'D:/File_conv/phototest.tif')))                #
> print(pytesseract.image_to_string(Image.open('test-european.jpg'),
> lang='fra'))                                  #Same error

对 image_to_string 的调用会生成 Windows Error[Error 2] :

> > text = pytesseract.image_to_string(im)
> >Traceback (most recent call last):
> 
>   File "<ipython-input-92-1f75dd6f29f3>", line 1, in <module>
>     text = pytesseract.image_to_string(im)
> 
>   File "C:\Program Files
> (x86)\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line
> 161, in image_to_string
>     boxes=boxes,
> 
>   File "C:\Program Files
> (x86)\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line
> 94, in run_tesseract
>     proc = subprocess.Popen(command,
> 
>   File "C:\Program Files (x86)\Anaconda2\lib\subprocess.py", line 711,
> in __init__
>     errread, errwrite)
> 
>   File "C:\Program Files (x86)\Anaconda2\lib\subprocess.py", line 959,
> in _execute_child
>     startupinfo)
> 
> WindowsError: [Error 2] The system cannot find the file specified

我已经尝试了所有我能找到的。我在 windows 上,conda 找不到发行版,所以我手动将 pytesser 提取到 Anaconda2\Lib,修改init.py以指向 tesseract 3.02 安装它给出了与此相同的错误。然后我尝试了 pytesseract 我可以通过它找到

>pip install pytesseract

系统变量 TESSDATA_PREFIX 和指针变量 image_to_string 指向正确:

> C:\Program Files (x86)\Tesseract-OCR

我无法弄清楚哪个地址引用出错了。


编辑:同样的错误出现在print command

  File "C:\Program Files (x86)\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
    print command

  File "C:\Program Files (x86)\Anaconda2\lib\subprocess.py", line 711, in __init__
    errread,

  File "C:\Program Files (x86)\Anaconda2\lib\subprocess.py", line 959, in _execute_child
    env,

WindowsError: [Error 2] The system cannot find the file specified

command对象在下面的函数中定义。添加到值检查的print语句在错误之前没有显示在控制台中,并且错误传播到if config:

    def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False, config=None):
    '''
    runs the command:
        `tesseract_cmd` `input_filename` `output_filename_base`

    returns the exit status of tesseract, as well as tesseract's stderr output

    '''
    print tesseract_cmd
    print input_filename
    print output_filename_base
    command = [tesseract_cmd, input_filename, output_filename_base]

    print config
    if lang is not None:
        command += ['-l', lang]

    if boxes:
        command += ['batch.nochop', 'makebox']

    if config:
        command += shlex.split(config)

    print command
    proc = subprocess.Popen(command,
            stderr=subprocess.PIPE)
    return (proc.wait(), proc.stderr.read())
4

1 回答 1

-2

我有同样的问题,这就是我所做的:

安慰

于 2017-03-11T19:12:06.020 回答