【问题标题】:Problems using Tesseract-OCR on Python在 Python 上使用 Tesseract-OCR 的问题
【发布时间】:2020-12-03 16:19:28
【问题描述】:

我是编程新手,我正在尝试使用 Tesseract OCR 来读取图像的文本,但我无法让它工作!我在我的环境中安装了 tesseract_OCR、pytesseract 和枕头。有人给点小费吗?

输入:

from PIL import Image 

import pytesseract

print( pytesseract.image_to_string( Image.open('phrase.jpg') ) ) 

输出:

 C:\Anaconda2\envs\ambiente36\python.exe 

 C:/Users/Simone/Desktop/curso_programacao/Ler_imagens/ler_imagens

Traceback (most recent call last):

File "C:\Anaconda2\envs\ambiente36\lib\site- 
packages\pytesseract\pytesseract.py", line 194, in run_and_get_output
run_tesseract(**kwargs)

File "C:\Anaconda2\envs\ambiente36\lib\site- 
packages\pytesseract\pytesseract.py", line 165, in run_tesseract
proc = subprocess.Popen(command, **subprocess_args())

File "C:\Anaconda2\envs\ambiente36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)

File "C:\Anaconda2\envs\ambiente36\lib\subprocess.py", line 997, in 
_execute_child 
startupinfo)

FileNotFoundError: [WinError 2] O sistema não pode encontrar o arquivo 
especificado

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/Simone/Desktop/curso_programacao/Ler_imagens/ler_imagens", 
line 6, in <module>
phrase = pytesseract.image_to_string(Image.open('phrase.jpg'))

File "C:\Anaconda2\envs\ambiente36\lib\site- 
packages\pytesseract\pytesseract.py", line 286, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)

File "C:\Anaconda2\envs\ambiente36\lib\site- 
packages\pytesseract\pytesseract.py", line 201, in run_and_get_output
raise TesseractNotFoundError()

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed 
or it's not in your path

【问题讨论】:

  • 你的图片文件和你的脚本在同一个文件夹吗?
  • 是的,它在同一个文件夹中。

标签: python anaconda tesseract


【解决方案1】:

在您的环境中配置 tessaract 应遵循的步骤 以下是您应该遵循的步骤

首先安装python和piphere是步骤 然后安装枕头,pytesseract 为here

from PIL import Image
from pytesser.pytesser import *

image_file = "FULL/PATH/TO/YOUR/IMAGE/image.png"
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

download pytessaract 的链接 你可以找到一个完整的例子here

【讨论】:

  • OP似乎使用python 3
  • 所以说我不能用anaconda环境做Tesseract-OCR,需要安装python和pip新建一个环境?
  • 如果你已经正确安装了anaconda python你不需要安装PIL..你只需要运行上面的例子
  • 如果你已经安装了 python-anaconda 然后下载下面的 zip 并将它解压到上面代码所在的同一目录然后运行示例code.google.com/p/pytesser/downloads/…
【解决方案2】:

似乎 Tesseract 未正确安装,或者 tesseract 的路径未指向实际安装 tesseract 的位置。

pytesseract.pytesseract.TesseractNotFoundError: tesseract 不是 已安装或不在您的路径中

我建议您首先通过关注the official documentation 来检查您的安装。

我最近编写了一个非常简单的 Tesseract 指南,但它应该使您能够编写您的第一个 OCR 脚本并清除我遇到的一些障碍,当事情没有我在文档中希望的那么清楚时。

如果您想查看它们,我在这里与您分享链接:

【讨论】:

    【解决方案3】:

    您需要使用可用的 Windows 安装程序 here 安装 tesseract。然后你应该将 python 包装器安装为:

    pip install pytesseract
    

    那么你还应该在导入pytesseract库后在你的脚本中设置tesseract路径(请不要忘记安装路径可能会在你的情况下被修改!):

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

    注意:在 Anaconda3 上测试没有任何问题。

    【讨论】:

      猜你喜欢
      • 2015-04-21
      • 2019-11-24
      • 2011-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      相关资源
      最近更新 更多