File size: 454 Bytes
c858478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def get_relation(subj_box, obj_box):
    sx, sy, sw, sh = subj_box
    ox, oy, ow, oh = obj_box

    # centers
    scx, scy = sx + sw / 2, sy + sh / 2
    ocx, ocy = ox + ow / 2, oy + oh / 2

    # vertical relation
    if scy < ocy - 20:
        return "above"
    elif scy > ocy + 20:
        return "below"

    # horizontal relation
    if scx < ocx - 20:
        return "left_of"
    elif scx > ocx + 20:
        return "right_of"

    return "near"