python计算两个矩形框重合百分比的实例
程序员文章站
2024-02-01 17:35:04
如下所示:
def mat_inter(box1,box2):
# 判断两个矩形是否相交
# box=(xa,ya,xb,yb)
x01, y01,...
如下所示:
def mat_inter(box1,box2): # 判断两个矩形是否相交 # box=(xa,ya,xb,yb) x01, y01, x02, y02 = box1 x11, y11, x12, y12 = box2 lx = abs((x01 + x02) / 2 - (x11 + x12) / 2) ly = abs((y01 + y02) / 2 - (y11 + y12) / 2) sax = abs(x01 - x02) sbx = abs(x11 - x12) say = abs(y01 - y02) sby = abs(y11 - y12) if lx <= (sax + sbx) / 2 and ly <= (say + sby) / 2: return true else: return false def solve_coincide(box1,box2): # box=(xa,ya,xb,yb) # 计算两个矩形框的重合度 if mat_inter(box1,box2)==true: x01, y01, x02, y02 = box1 x11, y11, x12, y12 = box2 col=min(x02,x12)-max(x01,x11) row=min(y02,y12)-max(y01,y11) intersection=col*row area1=(x02-x01)*(y02-y01) area2=(x12-x11)*(y12-y11) coincide=intersection/(area1+area2-intersection) return coincide else: return false
以上这篇python计算两个矩形框重合百分比的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。