在Windows上开始使用Python OCR?

时间:2015-06-28 19:37:56

标签: python python-imaging-library anaconda python-tesseract pytesser

我之前从未使用过python,我不知道从哪里开始。我的目标是获取图像数据,数字和多彩背景,并可靠地识别正确的字符。我查看了必要的工具,我找到了Anaconda python发行版,其中包括我可能需要的所有可能的软件包,以及tesseract-ocr和pytesser。

不幸的是,我迷失了如何开始。我使用PyCharm社区IDE并只是尝试按照本指南操作: http://www.manejandodatos.es/2014/11/ocr-python-easy/ 掌握OCR。

这是我使用的代码:

from PIL import Image
from pytesser import *

image_file = 'menu.jpg'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text

我相信我使用的Anaconda发行版有PIL,但我收到了这个错误:

C:\Users\diego_000\Anaconda\python.exe C:/Users/diego_000/PycharmProjects/untitled/test.py
Traceback (most recent call last):
  File "C:/Users/diego_000/PycharmProjects/untitled/test.py", line 2, in <module>
    from pytesser import *
  File "C:\Users\diego_000\PycharmProjects\untitled\pytesser.py", line 6, in <module>
    import Image
ImportError: No module named Image

Process finished with exit code 1

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:1)

您指向的文件说要使用

from PIL import Image

除了你使用

import Image

所以口译员正确地说:

ImportError: No module named Image

看起来好像你重新排序了行

from PIL import Image
from pytesser import *

并且pytesser对PIL的编码依赖性不正确。但我无法确定您提供的代码。