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;

}

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐