【问题标题】:Pytesser inaccuratePytesser 不准确
【发布时间】:2011-05-08 03:06:00
【问题描述】:

简单的问题。当我通过 pytesser 运行this 图像时,我得到$+s。我该如何解决?

编辑

所以...我的代码生成的图像类似于上面链接的图像,只是数字不同,并且应该解决简单的数学问题,如果我能从图片中得到的只是$+s,这显然是不可能的

这是我目前使用的代码:

from pytesser import *

time.sleep(2)
i = 0
operator = "+"
while i < 100:
    time.sleep(.1);
    img = ImageGrab.grab((349, 197, 349 + 452, 197 + 180))
    equation = image_to_string(img)

然后我将继续解析equation...,只要我让 pytesser 工作。

【问题讨论】:

  • 想解释一下为什么这被否决了吗?
  • @TheAdamGaskins:是的,我可以,这个问题需要更多信息,例如您的相关代码是什么,如果您可以发布到目前为止您尝试修复的内容,那就太好了它,所以人们没有“做”
  • 抱歉,由于某种原因无法编辑前一个,我是说,这样回答您问题的人就不必为您做所有繁重的工作,这应该是合作,如果您添加更多信息并使其成为一个完整的问题,我将删除我的反对票。
  • 如果没有更多上下文,例如您用于通过 pytesser 运行图像的确切代码等,真的很难准确地回答这个问题。

标签: python ocr


【解决方案1】:

试试我的小功能。我从svn repo 运行tesseract,所以我的结果可能更准确。

我在 Linux 上,所以在 Windows 上,我想您必须将 tesseract 替换为 tesseract.exe 才能使其正常工作。

import tempfile, subprocess

def ocr(image):
  tempFile = tempfile.NamedTemporaryFile(delete = False)

  process = subprocess.Popen(['tesseract', image, tempFile.name], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.STDOUT)
  process.communicate()

  handle = open(tempFile.name + '.txt', 'r').read()

  return handle

还有一个 Python 会话示例:

>>> import tempfile, subprocess
>>> def ocr(image):
...   tempFile = tempfile.NamedTemporaryFile(delete = False)
...   process = subprocess.Popen(['tesseract', image, tempFile.name], stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.STDOUT)
...   process.communicate()
...   handle = open(tempFile.name + '.txt', 'r').read()
...   return handle
... 
>>> print ocr('326_fail.jpg')
0+1

【讨论】:

  • 您使用的是非常旧的 Python 版本。我在 2.7 和 3.0 上这样做!
【解决方案2】:

如果你在 linux 中,使用 gocr 更准确。你可以通过

os.system("/usr/bin/gocr %s") % (sample_image)

并使用 stdout 中的 readlines 将输出结果操作为您想要的所有内容(即从 gocr 为特定变量创建输出)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 2023-03-16
    • 2013-09-21
    • 2021-07-28
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多