Pytesseract:FileNotFound

时间:2017-06-05 18:27:47

标签: python python-3.x ocr tesseract python-tesseract

我使用此代码对Pytesser进行了一些测试:

from PIL import Image
import pytesseract

img = Image.open('pic.png')
img.load()
text = pytesseract.image_to_string(img)
print(text)

在Windows上运行Python 3.4

运行时,我得到了来自Pytesseract模块的错误:

Traceback (most recent call last):
   File "C:/Users/Gamer/Documents/Python/Bot/test.py", line 6, in <module>
      text = pytesseract.image_to_string(img)
   File "C:\Python34\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
      config=config)
File "C:\Python34\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
   proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Python34\lib\subprocess.py", line 859, in __init__
   restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child
   startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我是安装模块的新手,这可能源于Tesseract-OCR或模块的错误安装或设置。

非常感谢任何帮助,

-Niall

2 个答案:

答案 0 :(得分:1)

我在安装tesseract方面没有任何问题,但我在UB Mannheim安装人员中使用了Tesseract:

https://github.com/UB-Mannheim/tesseract/wiki

您还需要安装pytesseract:

pip3.6 install pytesseract

看来Python在查找图像位置时遇到了问题。我建议使用带有图像路径的变量集来排除任何与PATH相关的问题。这是一个例子:

#Path to image folder    
src_path = "C:\\Users\\USERNAME\\Documents\\OCR\\"

#Run OCR on image    
text = pytesseract.image_to_string(Image.open(src_path + "pic.png"))

#Print OCR result
print (text)

答案 1 :(得分:0)

正如'st0le'评论的那样,结果是需要正确定义OCR-Tesseract的路径,而不是图像的路径。

我认为我只是为那些遇到类似问题的人解决这个问题,因为我现在已经开始工作了。

相关问题