SceneGraphNet / src /spatial_rules.py
Kalp Kanungo
Initial commit - Multimodal AI project
c858478
raw
history blame contribute delete
454 Bytes
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"