Skip to content Skip to sidebar Skip to footer

How To Detect All Boxes For Inputting Letters In Forms For A Particular Field?

It is required to recognize text from forms with boxes given for each character input. I have tried using bounding box for each input and cropping that particular input, i.e I can

Solution 1:

I know I'm a bit late to the party :) but in case somebody would be looking for solution to this problem - I recently came up with a python package that deals with this exact problem. I called it BoxDetect and after installing it through:

pip install boxdetect

You can try something like this:

from boxdetect import config

config.min_w, config.max_w = (20,50)
config.min_h, config.max_h = (20,50)
config.scaling_factors = [0.4]
config.dilation_iterations = 0
config.wh_ratio_range = (0.5, 2.0)
config.group_size_range = (1, 100)
config.horizontal_max_distance_multiplier = 2from boxdetect.pipelines import get_boxes

image_path = "dumpster/m1nda.jpg"
rects, grouped_rects, org_image, output_image = get_boxes(image_path, config, plot=False)


import matplotlib.pyplot as plt

print("======================")
print("Individual boxes (green): ", rects)
print("======================")
print("Grouped boxes (red): ", grouped_rects)
print("======================")
plt.figure(figsize=(25,25))
plt.imshow(output_image)
plt.show()

It returns bounding rectangle coords of all the rectangle boxes, grouped boxes forming long entry fields and visualization on the form image:

Processing file:dumpster/m1nda.jpg======================Individualboxes(green):  [[1153 1873   2626]
 [1125 1873   2427]
 [1098 1873   2426]
 ...
 [ 5585514228]
 [ 5145514228]
 [ 4685514228]]
======================Groupedboxes(red):  [(468, 551, 457, 29), (424, 728, 47, 45), (608, 728, 31, 45), (698, 728, 33, 45), (864, 728, 31, 45), (1059, 728, 47, 45), (456, 792, 763, 29), (456, 842, 763, 28), (456, 891, 763, 29), (249, 969, 961, 28), (249, 1017, 962, 28), (700, 1064, 39, 32), (870, 1064, 41, 32), (376, 1124, 45, 45), (626, 1124, 29, 45), (750, 1124, 27, 45), (875, 1124, 41, 45), (1054, 1124, 28, 45), (507, 1188, 706, 29), (507, 1238, 706, 28), (507, 1287, 706, 29), (718, 1335, 36, 31), (856, 1335, 35, 31), (1008, 1335, 34, 32), (260, 1438, 51, 37), (344, 1438, 56, 37), (505, 1443, 98, 27), (371, 1530, 31, 31), (539, 1530, 31, 31), (486, 1636, 694, 28), (486, 1684, 694, 28), (486, 1731, 694, 29), (486, 1825, 694, 29), (486, 1873, 694, 28)]
======================

enter image description here

Post a Comment for "How To Detect All Boxes For Inputting Letters In Forms For A Particular Field?"