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
Try using Stroke Width Transform. Python 3 implementation of the algorithm is present here at SWTloc
pip install swtloc
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'])
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