您的位置:首页 > 运维架构

Opencv求两个矩形是否相交,以及相交的比值

2013-03-30 17:14 337 查看
在图像处理中经常会遇到判断两个矩形是否相交,以及相交的比例的情况,下面是来自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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenCV周末提高