def compute_iou(bbox1, bbox2):
    """
    Compute IOU metric value (as well as precision and recall) between two bounding boxes.

    param bbox1: (rmin, rmax, cmin, cmax) detected bounding box 
    param bbox2: (rmin, rmax, cmin, cmax) ground-truth bounding box

    return: (IOU metric, precision, recall) tuple of results
    """
    # intersection rectangle coordinates
    x1 = max(bbox1[2], bbox2[2])
    y1 = max(bbox1[0], bbox2[0])
    x2 = min(bbox1[3], bbox2[3])
    y2 = min(bbox1[1], bbox2[1])

    intersection = max(0, x2 - x1 + 1) * max(0, y2 - y1 + 1)
    area1 = (bbox1[1] - bbox1[0] + 1) * (bbox1[3] - bbox1[2] + 1) # detection
    area2 = (bbox2[1] - bbox2[0] + 1) * (bbox2[3] - bbox2[2] + 1) # real

    # Precision: intersection / detection_bounding_box
    # Recall: intersection / real_object_boudnding_box
    prec = intersection / area1
    rec = intersection / area2

    return intersection / (area1 + area2 - intersection), prec, rec