简单的问题。当我通过pytesser运行这映像时,我得到了$+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
..。一旦我开始工作。
发布于 2011-05-08 03:54:10
试试我的小功能。我正在运行tesseract
从svn
回购,所以我的结果可能更准确。
我在Linux上,所以在Windows上,我想你必须用tesseract.exe
代替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
发布于 2011-05-08 13:51:16
如果您使用的是linux,那么使用gocr会更准确。你可以用它
os.system("/usr/bin/gocr %s") % (sample_image)
并使用stdout中的readline操作输出结果到您想要的任何东西(即为特定变量创建gocr的输出)。
https://stackoverflow.com/questions/5925344
复制相似问题