def xywh_iou(box1,box2):
    """
    calculate iou between box1 and box2
    :param box1: (4, ), format (left, upper, width, height)
    :param box2: (4, ), format (left, upper, width, height)
    :return: float, iou score
    """
    l_max = max(box1[0], box2[0])
    r_min = min(box1[0]+box1[2]-1, box2[0]+box2[2]-1)
    u_max = max(box1[1], box2[1])
    b_min = min(box1[1]+box1[3]-1, box2[1]+box2[3]-1)

    if l_max>=r_min or u_max>=b_min:
        return 0.
    else:
        area1 = box1[2]*box1[3]
        area2 = box2[2]*box2[3]
        area_i = (b_min-u_max)*(r_min-l_max)
        return area_i*1.0/(area1+area2-area_i)