def IoU(boxA, boxB):
    """
    Computes the Intersection over Union (IoU) metric, given
    two bounding boxes.
    Input:
    "boxA": bounding box A
    "boxB": bounding box B
    Output:
    "score": IoU score
    """

    # Compute the intersection points of the two BBs
    xLeft = max(boxA[0], boxB[0])
    yLeft = max(boxA[1], boxB[1])
    xRight = min(boxA[2], boxB[2])
    yRight = min(boxA[3], boxB[3])

    # Compute the area of the intersection rectangle
    interArea = max(0, xRight - xLeft + 1) * max(0, yRight - yLeft + 1)    

    # Compute the area of both boxA and boxB rectangles
    boxA_area = (boxA[2]-boxA[0] + 1)*(boxA[3]-boxA[1] + 1)
    boxB_area = (boxB[2]-boxB[0] + 1)*(boxB[3]-boxB[1] + 1)

    # Compute the intersection over union
    score = interArea / float(boxA_area + boxB_area - interArea)

    return score