【发布时间】:2011-01-25 23:58:10
【问题描述】:
我最近看到有人穿着一件背面印有 Perl 代码的 T 恤。我拍了一张照片,剪掉了代码:
接下来我尝试通过 OCR 从图像中提取代码,因此我安装了 Tesseract OCR 及其 Python 绑定 pytesser。
Pytesser 仅适用于 TIFF 图像,因此我在 Gimp 中转换图像并输入以下代码(Ubuntu 9.10):
>>> from pytesser import *
>>> image = Image.open('code.tif')
>>> print image_to_string(image)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pytesser.py", line 30, in image_to_string
util.image_to_scratch(im, scratch_image_name)
File "util.py", line 7, in image_to_scratch
im.save(scratch_image_name, dpi=(200,200))
File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1406, in save
save_handler(self, fp, filename)
File "/usr/lib/python2.6/dist-packages/PIL/BmpImagePlugin.py", line 197, in _save
raise IOError("cannot write mode %s as BMP" % im.mode)
IOError: cannot write mode RGBA as BMP
>>> r,g,b,a = image.split()
>>> img = Image.merge("RGB", (r,g,b))
>>> print image_to_string(img)
Tesseract Open Source OCR Engine
éi _ l_` _ t
’ ‘" fY`
{ W IKQW
· __·_ ‘ ·-»·
:W Z
·· I A n 1
;f
` `
`T .' V _ ‘
I {Z.; » ;,. , ; y i- 4 : %:,,
`· » V; ` ?
‘,—·.
H***li¥v·•·}I§¢ ` _ »¢is5#__·¤G$++}§;“»‘7·
71 ’ Q { NH IQ
ytéggygi { ;g¤qg;gm·;,g(g,,3) {3;;+-
§ {Jf**$d$ }‘$p•¢L#d¤ Sc}
» i ` i A1:
这显然是来自 OCR 引擎的胡言乱语。所以,我的问题是:
- 我必须做些什么才能从 Tesseract 中获得更好的 OCR 结果?
- 或者,还有其他人能以其他方式从上图中提取代码吗?
【问题讨论】:
-
我认为实际上 is 有效 perl...
-
你可以重新输入。这肯定会更快,因为它似乎是一个一次性的项目。
-
静一静,这看起来很有趣(谁知道它是否是一次性的?)
-
有史以来最好的问题!!您为什么不尝试将其发布到biostar.stackexchange.com/questions?
-
呃……那么为什么社区维基警察会查到这个?