def match_bounding_boxes(detected_bbox, ground_truth):
    """
    Compare a detected bounding box with the ground truth box by intersection/union.
    :param detected_bbox: vision_msgs/BoundingBox2D
    :param ground_truth: vision_msgs/BoundingBox2D
    :return: likelihood of bounding boxes matching
    """
    detected_corners = detected_bbox.get_corners()
    ground_truth_corners = ground_truth.get_corners()
    x1 = max(detected_corners[0], ground_truth_corners[0])
    y1 = max(detected_corners[1], ground_truth_corners[1])
    x2 = min(detected_corners[2], ground_truth_corners[2])
    y2 = min(detected_corners[3], ground_truth_corners[3])

    # catch non-overlapping bounding boxes (use absolute values)
    width = x2-x1
    height = y2-y1

    if width < 0 or height < 0:
        return 0.0

    area_of_intersection = width*height
    if area_of_intersection < 0:
        print("ERROR")
    area_detected_bbox = detected_bbox.width*detected_bbox.height
    area_ground_truth_bbox = ground_truth.width * ground_truth.height
    area_of_union = area_detected_bbox+area_ground_truth_bbox-area_of_intersection

    likelihood = area_of_intersection / area_of_union

    return likelihood