aihot  2017-05-06 07:39:28  OpenCV |   查看评论   

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

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

 

[cpp]   
 
 
  1. float bbOverlap(const BoundingBox& box1,const BoundingBox& box2)  
  2. {  
  3.   if (box1.x > box2.x+box2.width) { return 0.0; }  
  4.   if (box1.y > box2.y+box2.height) { return 0.0; }  
  5.   if (box1.x+box1.width < box2.x) { return 0.0; }  
  6.   if (box1.y+box1.height < box2.y) { return 0.0; }  
  7.   float colInt =  min(box1.x+box1.width,box2.x+box2.width) - max(box1.x, box2.x);  
  8.   float rowInt =  min(box1.y+box1.height,box2.y+box2.height) - max(box1.y,box2.y);  
  9.   float intersection = colInt * rowInt;  
 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自Opencv求两个矩形是否相交,以及相交的比值

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]