Ask Your Question

# Revision history [back]

Ordinary I use the following metric: area(intersection(rect1 & rect2)) / area(union(rect1&rect2)) > 0.5

Ordinary I use the following metric: area(intersection(rect1 & rect2)) area(intersection(rect1,rect2)) / area(union(rect1&rect2)) area(union(rect1,rect2)) > 0.5

Ordinary I use the following metric: area(intersection(rect1,rect2)) / area(union(rect1,rect2)) > 0.5

If you use the C++ way (cv::Rect), you can easily say

interesect  = r1 & r2;

for intersection calculation.

For CvRect:

CvRect intersect(CvRect r1, CvRect r2)
{
CvRect intersection;

// find overlapping region
intersection.x = (r1.x < r2.x) ? r2.x : r1.x;
intersection.y = (r1.y < r2.y) ? r2.y : r1.y;
intersection.width = (r1.x + r1.width < r2.x + r2.width) ?
r1.x + r1.width : r2.x + r2.width;
intersection.width -= intersection.x;
intersection.height = (r1.y + r1.height < r2.y + r2.height) ?
r1.y + r1.height : r2.y + r2.height;
intersection.height -= intersection.y;

// check for non-overlapping regions
if ((intersection.width <= 0) || (intersection.height <= 0)) {
intersection = cvRect(0, 0, 0, 0);
}

return intersection;
}