opencv 中两个rect相交
2015-07-27 16:04
405 查看
在对opencv进行应用中,我们常会应用到rect之间的关系,可以采用如下方法来实现:
bool rectA_intersect_rectB(cv::Rect rectA, cv::Rect rectB)
如果rectA与rectB相交,则返回true,这里的相交没有包含的概念,如果要用到包含则可根据下面代码进行修改
bool rectA_intersect_rectB(cv::Rect rectA, cv::Rect rectB)
如果rectA与rectB相交,则返回true,这里的相交没有包含的概念,如果要用到包含则可根据下面代码进行修改
bool rectA_intersect_rectB(cv::Rect rectA, cv::Rect rectB) { if ( rectA.x > rectB.x + rectB.width ) { return false; } if ( rectA.y > rectB.y + rectB.height ) { return false; } if ( (rectA.x + rectA.width) < rectB.x ) { return false; } if ( (rectA.y + rectA.height) < rectB.y ) { return false; } float colInt = min(rectA.x+rectA.width,rectB.x+rectB.width) - max(rectA.x, rectB.x); float rowInt = min(rectA.y+rectA.height,rectB.y+rectB.height) - max(rectA.y,rectB.y); float intersection = colInt * rowInt; float areaA = rectA.width * rectA.height; float areaB = rectB.width * rectB.height; float intersectionPercent = intersection / (areaA + areaB - intersection); if ( (0 < intersectionPercent)&&(intersectionPercent < 1)&&(intersection != areaA)&&(intersection != areaB) ) { return true; } return false; }
相关文章推荐
- linux 逻辑卷创建、增加与减少
- 某电商网站线上drbd+heartbeat+nfs配置
- sublime text 2 for linux [ubuntu] 安装与破解方法全解
- MapReduce架构和算法(2)
- Redhat 7 配置-----破解ROOT密码
- Linux配置nodejs
- nginx 域名(虚拟)部署nodejs项目
- Linux文件系统的管理
- Hadoop快速入门
- 属性通知之INotifyPropertyChanged
- Linux_LVM Couldn't find device with uuid
- JSVC启动Tomcat
- 浅谈Linux进程
- 浅谈Linux进程
- linux下错误的捕获:errno和strerror的使用
- RHEL5U8配置Centos yum源
- 让mahout0.7在hadoop2.0环境下运行
- tomcat结合nginx使用小结
- linux CR2 to JPG
- linux 精灵函数