我有一张黑白图片,里面的字符之间有一些空格隔开。检测每个字母的矩形(顶部、底部、左侧和右侧像素)的最佳方法是什么?
发布于 2012-03-09 12:15:51
PIL是一个相当简单的图像处理包-它可以加载/保存裁剪,执行基本变换等-但它完全缺乏OCR基本的“计算机科学”过滤器(这些过滤器可以在Tesseract使用的Leptonica库中找到)。如果Tesseract无法识别你需要的东西,就像你在评论中所说的那样,准备好阅读你自己的OCR软件。
如果你所需要的只是每个字符的边界矩形,那么这就容易了一个数量级--使用PIL甚至可能是可行的,但同样地,使用Python-leptonica绑定会更容易--你可以使用leptonica.functions.pixFindRectangleComps --函数的heklp是:
pixFindRectangleComps(*args)
('PIX', '*pixs')
('l_int32', 'dist')
('l_int32', 'minw')
('l_int32', 'minh')
pixFindRectangleComps()
Input: pixs (1 bpp)
dist (max distance allowed between bounding box and nearest
foreground pixel within it)
minw, minh (minimum size in each direction as a requirement
for a conforming rectangle)
Return: boxa (of components that conform), or null on error
Notes:
(1) This applies the function pixConformsToRectangle() to
each 8-c.c. in pixs, and returns a boxa containing the
regions of all components that are conforming.
(2) Conforming components must satisfy both the size constraint
given by @minsize and the slop in conforming to a rectangle
determined by @dist.
(END)
其中pix是leptonica库图像对象,"boxa“是矩形对象的列表。
我已经开始了Leptonica的Python绑定,目前可以在:http://code.google.com/p/pylepthonica/wiki/Home-我没有在这些绑定中投入太多精力,但它们在leptonica 1.67 (现在已经+/-两年了)上应该可以很好地工作。
https://stackoverflow.com/questions/9626838
复制相似问题