Python + OpenCV: OCR Image Segmentation

后端 未结 4 829
名媛妹妹
名媛妹妹 2021-01-30 11:56

I am trying to do OCR from this toy example of Receipts. Using Python 2.7 and OpenCV 3.1.

Grayscale + Blur + External Edge Detection + Segmentation of each area

4条回答
  •  春和景丽
    2021-01-30 12:13

    Try using Stroke Width Transform. Python 3 implementation of the algorithm is present here at SWTloc

    Install the Library

    pip install swtloc
    

    Run the swttransform

    from swtloc import SWTLocalizer
    from swtloc.utils import imgshowN, imgshow
    
    swtl = SWTLocalizer()
    imgpath = ...
    swtl.swttransform(imgpaths=imgpath, text_mode = 'lb_df', gs_blurr=False ,
                      minrsw = 3, maxrsw = 10, max_angledev = np.pi/3)
    mgshowN([swtl.orig_img, swtl.swt_mat, swtl.swt_labelled3C],
            ['Original Image', 'Stroke Width Transform', 'Connected Components'])
    

    Run the Grouping of texts

    respacket = swtl.get_grouped(lookup_radii_multiplier=.8, sw_ratio=2,
                     cl_deviat=[13,13,13], ht_ratio=2, 
                     ar_ratio=4, ang_deviat=30)
    
    grouped_labels = respacket[0]
    grouped_bubblebbox = respacket[1]
    grouped_annot_bubble = respacket[2]
    
    imgshowN([swtl.orig_img, grouped_annot_bubble],
            ['Original', 'Grouped Bubble BBox Annotation'])
    

    There are multiple parameters in the of the swttransform function and get_grouped function that you can play around with to get the desired results.

    Full Disclosure : I am the author of this library

提交回复
热议问题