Permalink
Browse files

use nms.doesOverlap for test

  • Loading branch information...
1 parent 1760e7d commit 5b3af91bbca71ef40ec10b27ca062665b2524b68 @harthur committed Nov 2, 2012
Showing with 5 additions and 31 deletions.
  1. +4 −1 nms.js
  2. +1 −30 testing/test.js
View
@@ -1,6 +1,7 @@
/* non-maximum suppression - combine overlapping rects into the strongest one */
exports.combineOverlaps = combineOverlaps;
+exports.doesOverlap = doesOverlap;
/* rects is an array of objects that look like:
* {
@@ -10,7 +11,7 @@ exports.combineOverlaps = combineOverlaps;
* height: // height of rect,
* prob: // the higher, the more likely it will suppress other rects
* }
- *
+ *
* minRatio is the min ratio of intersection area to union area of two rects
* to qualify them as overlapping.
*
@@ -47,6 +48,8 @@ function combineOverlaps(rects, minRatio, minOverlaps) {
}
function doesOverlap(r1, r2, minRatio) {
+ minRatio = minRatio || 0.5;
+
var overlapW, overlapH;
if (r1.x > r2.x) {
overlapW = Math.min((r2.x + r2.width) - r1.x, r1.width);
View
@@ -104,7 +104,7 @@ function testImage(image, callback) {
var found = false;
cats.forEach(function(cat) {
- var overlaps = doesOverlap(cat, rect);
+ var overlaps = nms.doesOverlap(cat, rect);
if (overlaps) {
found = true;
truePos++;
@@ -159,32 +159,3 @@ function printDots() {
// hide the cursor when printing the dots
charm.cursor(false);
}
-
-function doesOverlap(cat, rect) {
- var overlapW, overlapH;
-
- if (cat.x > rect.x) {
- overlapW = Math.min((rect.x + rect.width) - cat.x, cat.width);
- }
- else {
- overlapW = Math.min((cat.x + cat.width) - rect.x, rect.width);
- }
-
- if (cat.y > rect.y) {
- overlapH = Math.min((rect.y + rect.height) - cat.y, cat.height);
- }
- else {
- overlapH = Math.min((cat.y + cat.height) - rect.y, rect.height);
- }
-
- if (overlapW <= 0 || overlapH <= 0) {
- return false;
- }
- var intersect = overlapW * overlapH;
- var union = (cat.width * cat.height) + (rect.width * rect.height) - (intersect * 2);
-
- if (intersect / union > 0.5) {
- return true;
- }
- return false;
-}

0 comments on commit 5b3af91

Please sign in to comment.