in ocr/utils/iam_dataset.py [0:0]
def _get_bb_of_item(self, item, height, width):
''' Helper function to find the bounding box (bb) of an item in the xml file.
All the characters within the item are found and the left-most (min) and right-most (max + length)
are found.
The bounding box emcompasses the left and right most characters in the x and y direction.
Parameter
---------
item: xml.etree object for a word/line/form.
height: int
Height of the form to calculate percentages of bounding boxes
width: int
Width of the form to calculate percentages of bounding boxes
Returns
-------
list
The bounding box [x, y, w, h] in percentages that encompasses the item.
'''
character_list = [a for a in item.iter("cmp")]
if len(character_list) == 0: # To account for some punctuations that have no words
return None
x1 = np.min([int(a.attrib['x']) for a in character_list])
y1 = np.min([int(a.attrib['y']) for a in character_list])
x2 = np.max([int(a.attrib['x']) + int(a.attrib['width']) for a in character_list])
y2 = np.max([int(a.attrib['y']) + int(a.attrib['height'])for a in character_list])
x1 = float(x1) / width
x2 = float(x2) / width
y1 = float(y1) / height
y2 = float(y2) / height
bb = [x1, y1, x2 - x1, y2 - y1]
return bb