def calc_iou(recs):
    """
    recs: A tuple containing two tuples, each representing a rectangle
    returns: Float. The calculated intersection over union metric.  
    """
    recA, recB = recs
    xminA, yminA, xmaxA, ymaxA = recA
    areaA = (xmaxA-xminA) * (ymaxA-yminA)
    
    xminB, yminB, xmaxB, ymaxB = recB
    areaB = (xmaxB-xminB) * (ymaxB-yminB)
    
    diffx = min(xmaxA, xmaxB) - max(xminA, xminB)
    diffy = min(ymaxA, ymaxB) - max(yminA, yminB)
    

    if (diffx>=0) & (diffy>=0):
        intersection= diffx * diffy    
    else:
        intersection=0
        
    union = areaA + areaB - intersection

    return intersection/union