Skip to content
This repository
Browse code

use nms.doesOverlap for test

  • Loading branch information...
commit 5b3af91bbca71ef40ec10b27ca062665b2524b68 1 parent 1760e7d
Heather Arthur authored November 01, 2012

Showing 2 changed files with 5 additions and 31 deletions. Show diff stats Hide diff stats

  1. 5  nms.js
  2. 31  testing/test.js
5  nms.js
... ...
@@ -1,6 +1,7 @@
1 1
 /* non-maximum suppression - combine overlapping rects into the strongest one */
2 2
 
3 3
 exports.combineOverlaps = combineOverlaps;
  4
+exports.doesOverlap = doesOverlap;
4 5
 
5 6
 /* rects is an array of objects that look like:
6 7
  *  {
@@ -10,7 +11,7 @@ exports.combineOverlaps = combineOverlaps;
10 11
  *    height: // height of rect,
11 12
  *    prob: // the higher, the more likely it will suppress other rects
12 13
  *  }
13  
- * 
  14
+ *
14 15
  * minRatio is the min ratio of intersection area to union area of two rects
15 16
  * to qualify them as overlapping.
16 17
  *
@@ -47,6 +48,8 @@ function combineOverlaps(rects, minRatio, minOverlaps) {
47 48
 }
48 49
 
49 50
 function doesOverlap(r1, r2, minRatio) {
  51
+  minRatio = minRatio || 0.5;
  52
+
50 53
   var overlapW, overlapH;
51 54
   if (r1.x > r2.x) {
52 55
     overlapW = Math.min((r2.x + r2.width) - r1.x, r1.width);
31  testing/test.js
@@ -104,7 +104,7 @@ function testImage(image, callback) {
104 104
 
105 105
       var found = false;
106 106
       cats.forEach(function(cat) {
107  
-        var overlaps = doesOverlap(cat, rect);
  107
+        var overlaps = nms.doesOverlap(cat, rect);
108 108
         if (overlaps) {
109 109
           found = true;
110 110
           truePos++;
@@ -159,32 +159,3 @@ function printDots() {
159 159
   // hide the cursor when printing the dots
160 160
   charm.cursor(false);
161 161
 }
162  
-
163  
-function doesOverlap(cat, rect) {
164  
-  var overlapW, overlapH;
165  
-
166  
-  if (cat.x > rect.x) {
167  
-    overlapW = Math.min((rect.x + rect.width) - cat.x, cat.width);
168  
-  }
169  
-  else {
170  
-    overlapW = Math.min((cat.x + cat.width) - rect.x, rect.width);
171  
-  }
172  
-
173  
-  if (cat.y > rect.y) {
174  
-    overlapH = Math.min((rect.y + rect.height) - cat.y, cat.height);
175  
-  }
176  
-  else {
177  
-    overlapH = Math.min((cat.y + cat.height) - rect.y, rect.height);
178  
-  }
179  
-
180  
-  if (overlapW <= 0 || overlapH <= 0) {
181  
-    return false;
182  
-  }
183  
-  var intersect = overlapW * overlapH;
184  
-  var union = (cat.width * cat.height) + (rect.width * rect.height) - (intersect * 2);
185  
-
186  
-  if (intersect / union > 0.5) {
187  
-    return true;
188  
-  }
189  
-  return false;
190  
-}

0 notes on commit 5b3af91

Please sign in to comment.
Something went wrong with that request. Please try again.