赞
踩
float intersectRect(const cv::Rect& rectA, const cv::Rect& rectB, cv::Rect& intersectRect){
if (rectA.x > rectB.x + rectB.width) { return 0.; }
if (rectA.y > rectB.y + rectB.height) { return 0.; }
if ((rectA.x + rectA.width) < rectB.x) { return 0.; }
if ((rectA.y + rectA.height) < rectB.y) { return 0.; }
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);
intersectRect.x = max(rectA.x, rectB.x);
intersectRect.y = max(rectA.y, rectB.y);
intersectRect.width = min(rectA.x + rectA.width, rectB.x + rectB.width) - intersectRect.x;
intersectRect.height = min(rectA.y + rectA.height, rectB.y + rectB.height) - intersectRect.y;
return intersectionPercent;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。