Exemple #1
0
def get_bounding_box_intersection_area_ratio(
        bounding_box_1: BoundingBox,
        bounding_box_2: BoundingBox,
        empty_ratio: float = 0.0) -> float:
    max_area = max(bounding_box_1.area, bounding_box_2.area)
    if not max_area:
        return empty_ratio
    intersection_area = bounding_box_1.intersection(bounding_box_2).area
    return intersection_area / max_area
def is_bounding_box_overlapping_with_any_bounding_boxes(
        bounding_box: BoundingBox,
        other_bounding_boxes: Sequence[BoundingBox],
        max_overlap_ratio: float = 0.1) -> bool:
    bounding_box_area = bounding_box.area
    for other_bounding_box in other_bounding_boxes:
        intersection_bounding_box = bounding_box.intersection(
            other_bounding_box)
        if not intersection_bounding_box:
            continue
        if intersection_bounding_box.area / bounding_box_area >= max_overlap_ratio:
            return True
    return False
 def test_should_calculate_intersection_with_identical_bounding_box(self):
     bounding_box = BoundingBox(110, 120, 50, 60)
     assert (
         bounding_box.intersection(bounding_box) == bounding_box
     )