def rectangle_intersect(lu1, w1, h1, lu2, w2, h2):
    """
    https://stackoverflow.com/questions/4549544/

    :param lu1: Left upper 1 (u,v)
    :param w1:
    :param h1:
    :param lu2:  Left upper 2 (u,v)
    :param w2:
    :param h2:
    :return: intersection region of each rectangle image frame
    (us1,vs1,ut1,vt1),(us2,vs2,ut2,vt2)
    """
    u1, v1 = lu1
    u2, v2 = lu2
    left = max(u1, u2)
    right = min(u1 + w1, u2 + w2)
    top = max(v1, v2)
    bottom = min(v1 + h1, v2 + h2)
    assert left < right and bottom > top  # Intersection in image space
    if left == u1:
        us1 = 0
        us2 = left - u2
    else:
        us2 = 0
        us1 = left - u1

    if right == u1 + w1:
        ut1 = w1
        ut2 = right - u2
    else:
        ut2 = w2
        ut1 = right - u1

    if top == v1:
        vs1 = 0
        vs2 = top - v2
    else:
        vs2 = 0
        vs1 = top - v1

    if bottom == v1 + h1:
        vt1 = h1
        vt2 = bottom - v2
    else:
        vt2 = h2
        vt1 = bottom - v1

    return (us1, vs1, ut1, vt1), (us2, vs2, ut2, vt2)