OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 04 Jul 2012 16:15:12 -0500Performance evaluation for detectionhttp://answers.opencv.org/question/117/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!Wed, 04 Jul 2012 15:14:53 -0500http://answers.opencv.org/question/117/performance-evaluation-for-detection/Answer by AlexanderShishkov for <p>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:</p>
<pre><code>if intersect.area() > (0.9*ref.area())
hit++
else
miss++
</code></pre>
<p>It is good enough to evaluate?
I have looked the code in <code>opencv_performance</code>, but did not understood well the metric used here. It is a code for rect intersection or another thing? </p>
<p>Thanks!</p>
http://answers.opencv.org/question/117/performance-evaluation-for-detection/?answer=118#post-id-118Ordinary 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;
} Wed, 04 Jul 2012 15:34:31 -0500http://answers.opencv.org/question/117/performance-evaluation-for-detection/?answer=118#post-id-118Comment by icedecker for <p>Ordinary I use the following metric:
area(intersection(rect1,rect2)) / area(union(rect1,rect2)) > 0.5</p>
<p>If you use the C++ way (cv::Rect), you can easily say</p>
<pre><code>interesect = r1 & r2;
</code></pre>
<p>for intersection calculation.</p>
<p>For CvRect:</p>
<pre><code>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;
}
</code></pre>
http://answers.opencv.org/question/117/performance-evaluation-for-detection/?comment=119#post-id-119Thanks, 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 rect_union = rect_det | rect_ref, right? Wed, 04 Jul 2012 15:57:40 -0500http://answers.opencv.org/question/117/performance-evaluation-for-detection/?comment=119#post-id-119Comment by icedecker for <p>Ordinary I use the following metric:
area(intersection(rect1,rect2)) / area(union(rect1,rect2)) > 0.5</p>
<p>If you use the C++ way (cv::Rect), you can easily say</p>
<pre><code>interesect = r1 & r2;
</code></pre>
<p>for intersection calculation.</p>
<p>For CvRect:</p>
<pre><code>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;
}
</code></pre>
http://answers.opencv.org/question/117/performance-evaluation-for-detection/?comment=121#post-id-121Yes, 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(). Wed, 04 Jul 2012 16:15:12 -0500http://answers.opencv.org/question/117/performance-evaluation-for-detection/?comment=121#post-id-121Comment by AlexanderShishkov for <p>Ordinary I use the following metric:
area(intersection(rect1,rect2)) / area(union(rect1,rect2)) > 0.5</p>
<p>If you use the C++ way (cv::Rect), you can easily say</p>
<pre><code>interesect = r1 & r2;
</code></pre>
<p>for intersection calculation.</p>
<p>For CvRect:</p>
<pre><code>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;
}
</code></pre>
http://answers.opencv.org/question/117/performance-evaluation-for-detection/?comment=120#post-id-120minunionrect = det | ref, for fair union area calculation you shoud write more complex codeWed, 04 Jul 2012 16:01:37 -0500http://answers.opencv.org/question/117/performance-evaluation-for-detection/?comment=120#post-id-120