题目
给两个rectangle,boxA:[x1,y1,x2,y2], boxB:[x3,y3,x4,y4]。前两个坐标代表upper left point,后两个座标代表bottom right point,并且假设x向右为正方向,y向下为正方向。主要思想是,相交的区域的upper left point是A和B upper left point中的一个,相交的区域的的bottom right point是A和B的bottom point中的一个。代码如下:
def cal_iou(boxA,boxB):
# the (x,y) of upper left point of intersect region will be the max of (x,y) of upper left point of boxA and boxB
xA = max(boxA[0],boxB[0])
yA = max(boxA[1],boxB[1])
# the (x,y) of bottom right point of intersect region will be the min of (x,y) of bottom right point of boxA and boxB
xB = min