# Performance evaluation for detection

I'm trying to evaluate some cascades I have trained with trainingcascade.cpp. So I would like to know if using the intersection of two rectangles (the reference rect and the detected rect) is a good metric. The criteria would be something:

if intersect.area() > (0.9*ref.area())
hit++
else
miss++


It is good enough to evaluate? I have looked the code in opencv_performance, but did not understood well the metric used here. It is a code for rect intersection or another thing?

Thanks!

edit retag close merge delete

Sort by » oldest newest most voted 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;
}

more

Thanks, Alexander! I'm doing in the C++ way. I thought that intersection would be sufficient, the use of union is a good idea. For the union, the code would be Rect rectunion = rectdet | rect_ref, right?

1

minunionrect = det | ref, for fair union area calculation you shoud write more complex code

1

Yes, for area of union, a bit of code is necessary. The calculation for union would be something like as: rect_union.area() = r1.area() + r2.area() - intersection.area().

Official site

GitHub

Wiki

Documentation