in src/co_op_translator/utils/vision/image_utils.py [0:0]
def group_bounding_boxes(original_boxes):
"""
Group bounding boxes into paragraphs based on x-coordinate proximity.
Args:
original_boxes (list): Flat list of bounding box dictionaries
Returns:
list: List of grouped bounding boxes (list of lists)
"""
if not original_boxes:
return []
grouped = []
current_group = [original_boxes[0]]
for box in original_boxes[1:]:
prev_x = current_group[-1]["bounding_box"][0]
curr_x = box["bounding_box"][0]
if abs(curr_x - prev_x) <= 5:
current_group.append(box)
else:
grouped.append(current_group)
current_group = [box]
grouped.append(current_group)
return grouped