python计算两个矩形框重合百分比的实例

yipeiwu_com6年前Python基础

如下所示:

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计算两个矩形框重合百分比的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 获取numpy.array索引值的实例

举个例子: q=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] 我想获取其中值等于7的那个值的下标,以便于用于其他计算。 如果使用np.where,...

Python中的特殊语法:filter、map、reduce、lambda介绍

filter(function, sequence):对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/T...

Python 循环语句之 while,for语句详解

循环语句(有两种): while 语句 for   语句 while 语句: 问题:输入一个整数n,让程序输出n行的: hello 1 hello 2 ....

pytorch中torch.max和Tensor.view函数用法详解

torch.max() 1. torch.max()简单来说是返回一个tensor中的最大值。 例如: >>> si=torch.randn(4,5) >&g...

浅谈PyQt5 的帮助文档查找方法,可以查看每个类的方法

浅谈PyQt5 的帮助文档查找方法,可以查看每个类的方法

事情是这样的,我在python中安装了PyQt5后,想查看QtGui模块中的类QMainWindow有哪些方法, 如何查看呢? 解决方法: 1、原来在安装PyQt5时相应的帮助文档已经在...