def get_outer_bounding_boxes(rectangles):
    """
    :param rectangles: list of bounding boxes (top, left, bottom, right)
    :return: outer bounding boxes (only the largest bbox when bboxes intersect)
    """
    if len(rectangles) == 0:
        return []
    outer_bboxes = [rectangles[0]]
    for bbox2 in rectangles[1:]:
        overlap_indexes = []
        for i, bbox1 in enumerate(outer_bboxes):  # TODO: optimize this !!
            if doOverlap(bbox1, bbox2):
                overlap_indexes.append(i)
        for i in overlap_indexes:
            bbox2 = mergeBboxes(bbox2, outer_bboxes[i])
        for i in sorted(overlap_indexes, reverse=True):
            del outer_bboxes[i]
        outer_bboxes.append(bbox2)
    return outer_bboxes
def get_outer_bounding_boxes ( rectangles ) : if len ( rectangles ) == 0 : return [ ] outer_bboxes = [ rectangles [ 0 ] ] for bbox2 in rectangles [ 1 : ] : overlap_indexes = [ ] for i , bbox1 in enumerate ( outer_bboxes ) : if doOverlap ( bbox1 , bbox2 ) : overlap_indexes . append ( i ) for i in overlap_indexes : bbox2 = mergeBboxes ( bbox2 , outer_bboxes [ i ] ) for i in sorted ( overlap_indexes , reverse = True ) : del outer_bboxes [ i ] outer_bboxes . append ( bbox2 ) return outer_bboxes
:param rectangles: list of bounding boxes (top, left, bottom, right)
    :return: outer bounding boxes (only the largest bbox when bboxes intersect)