2012-03-08 60 views
0

我有黑白图片,其中包含由一些空格分隔的字符。检测每个字母的矩形(顶部,底部,左侧和右侧像素)的最佳方法是什么?PIL - 如何检测字符?

+1

Tesseract OCR可以做到这一点 – wim 2012-03-08 23:44:01

+0

查找完全空白的列并将其用作分隔符... – 2012-03-08 23:59:48

+0

tesseract无法识别数学公式。我想通过分别识别每个角色来做到这一点。 – arts777 2012-03-09 00:00:26

回答

1

PIL是一个相当简单的图像处理软件包 - 它可以加载/保存作物,执行基本变换等等 - 但它完全缺乏OCR基本的“计算机科学”过滤器(这些过滤器可用于Leptonica库, Tesseract使用)。如果Tesseract无法识别您需要的内容,正如您在评论中说明的那样,请准备好阅读您自己的OCR软件的一些非常辛苦的工作。

如果你需要的是每个角色的边界矩形,那么这将是一个数量级更容易的事情 - 它甚至可以用PIL来实现,但是使用Python-leptonica绑定可以更容易地使用tit - 你可以使用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(现在是+/-两岁)