【问题标题】:How to fill the outline text by PIL to using tesseract?如何通过 PIL 填充大纲文本以使用 tesseract?
【发布时间】:2014-05-19 13:59:16
【问题描述】:

您好,我想使用 PIL 和 tesseract 对这张图片进行 ocr,通常它可以正常工作,尽管这张图片中的轮廓编号像 1148,但 tesseract 无法识别它。所以想用PIL把大纲文字1148填充成实心文字,但是不知道怎么做。任何帮助,将不胜感激。请。

这是我的代码:

api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", "0123456789.")
api.SetPageSegMode(tesseract.PSM_AUTO
pic = ImageGrab.grab((120,90,180,650)) 
pic = pic.filter(ImageFilter.CONTOUR)
pic.save("321.png")
mImgFile = "321.png"
mBuffer=open(mImgFile,"rb").read()
result = tesseract.ProcessPagesBuffer(mBuffer,len(mBuffer),api)
print result

【问题讨论】:

    标签: python-imaging-library ocr tesseract outline


    【解决方案1】:

    您可以在ImageDraw 中尝试实验性 floodfill() 功能。

    如果你能找出数字中的一些点,可以这样使用:

    from PIL import ImageColor, ImageDraw
    draw = ImageDraw.Draw(pic)
    
    point_inside_digit = (some_x, some_y)
    
    ImageDraw.floodfill(im, point_inside_digit, ImageColor.getrgb("black"))
    
    del draw
    

    除了白色之外,数字中还有一些蓝色和黄色,所以填充到黑色边框可能会更好:

    ImageDraw.floodfill(
        im, point_inside_digit, ImageColor.getrgb("black"),
        border=ImageColor.getrgb("black"))
    

    【讨论】:

    • 谢谢,我之前跳过了这个问题,所以没有快速回复。
    猜你喜欢
    • 2021-08-30
    • 2013-09-17
    • 1970-01-01
    • 2011-02-27
    • 2021-04-08
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    相关资源
    最近更新 更多