2011-05-08 50 views
4

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

编辑

所以......我的代码生成类似于上面链接,只是用不同的数字图像的图像,并且应该解决简单的数学问题,这显然是不可能的,如果我能得到出来的画面是$+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工作。

+0

小心解释为什么这是被拒绝的? – Entity 2011-05-08 03:19:45

+0

@TheAdamGaskins:是的,我可以,这个问题需要更多的信息,例如你的相关代码是什么,如果你可以发布你迄今为止想要修复的问题,那么这将是一件好事,所以人们不会“donshing – Trufa 2011-05-08 03:22:27

+1

抱歉,由于某种原因,我不能编辑前一个,因此,那些回答你问题的人不需要为你完成所有繁重的工作和所有的工作,这应该是如果你添加更多的信息并且把它作为一个完整的问题,我将删除我的downvote – Trufa 2011-05-08 03:24:28

回答

2

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

我在Linux上,所以在Windows上,我想你必须用tesseract.exe替换tesseract才能使它工作。

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 
+0

这似乎并没有编译与Python 2.4(我正在使用)... – Entity 2011-05-08 11:27:57

+0

这是错误:http://pastebin.com/Mdjv27ea – Entity 2011-05-08 11:29:56

+0

你使用的是一个真正旧版本的Python。我在2.7和3.0上做这个! – Blender 2011-05-08 22:15:45

1

,如果你在Linux的时候,使用GOCR更准确。你可以使用它来

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

和使用readlines方法从标准输出操纵输出结果给你想要的(即创建从GOCR输出特定变量)什么的一切。