设为首页 加入收藏

TOP

OpenCV求两个矩形是否相交,以及他们的重叠度
2014-11-24 03:14:30 来源: 作者: 【 】 浏览:1
Tags:OpenCV 两个 矩形 是否 相交 以及 他们 重叠

在图像处理中经常会遇到判断两个矩形是否相交,以及相交的比例的情况,下面是来自TLD算法中源码的求法:


float bbOverlap(const BoundingBox& box1,const BoundingBox& box2)
{
if (box1.x > box2.x+box2.width) { return 0.0; }
if (box1.y > box2.y+box2.height) { return 0.0; }
if (box1.x+box1.width < box2.x) { return 0.0; }
if (box1.y+box1.height < box2.y) { return 0.0; }
float colInt = min(box1.x+box1.width,box2.x+box2.width) - max(box1.x, box2.x);
float rowInt = min(box1.y+box1.height,box2.y+box2.height) - max(box1.y,box2.y);
float intersection = colInt * rowInt;
float area1 = box1.width*box1.height;
float area2 = box2.width*box2.height;
return intersection / (area1 + area2 - intersection);
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++中数值和字符串的转换 下一篇Hadoop序列化文件SequenceFile

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)
·Python超详细一条龙 (2025-12-24 18:49:42)
·【超详细】JDK 下载 (2025-12-24 18:19:32)
·Java_百度百科 (2025-12-24 18:19:29)