Made a change to 1D decoding which looks for 100% instead of 150% of the start and...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 15 Oct 2008 19:47:34 +0000 (19:47 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 15 Oct 2008 19:47:34 +0000 (19:47 +0000)
The result is complete elimination of all false positives in the new batch of 40 images I just checked in. Bettter than that, we come up with a net gain of 38 new barcodes decoded (counting rotation and try harder variations). We even get some of the reflective images that were impossible up to this point.

git-svn-id: http://zxing.googlecode.com/svn/trunk@620 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/oned/AbstractUPCEANReader.java
core/test/src/com/google/zxing/negative/FalsePositivesBlackBoxTestCase.java
core/test/src/com/google/zxing/negative/PartialBlackBoxTestCase.java
core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java
core/test/src/com/google/zxing/oned/UPCEBlackBox2TestCase.java
core/test/src/com/google/zxing/oned/UPCEBlackBox3ReflectiveTestCase.java

index 3ffc28b..c08f299 100644 (file)
@@ -35,7 +35,7 @@ import java.util.Hashtable;
  */
 public abstract class AbstractUPCEANReader extends AbstractOneDReader implements UPCEANReader {
 
-  private static final int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.40625f);
+  private static final int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
   private static final int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f);
 
   /**
@@ -92,9 +92,13 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
       startRange = findGuardPattern(row, nextStart, false, START_END_PATTERN);
       int start = startRange[0];
       nextStart = startRange[1];
-      // As a check, we want to see some white in front of this "start pattern",
-      // maybe as wide as the 150% of the start pattern itself?
-      foundStart = row.isRange(Math.max(0, start - (3 * (nextStart - start)) / 2), start, false);
+      // Make sure there is a quiet zone at least as big as the start pattern before the barcode. If
+      // this check would run off the left edge of the image, do not accept this barcode, as it is
+      // very likely to be a false positive.
+      int quietStart = start - (nextStart - start);
+      if (quietStart >= 0) {
+        foundStart = row.isRange(quietStart, start, false);
+      }
     }
     return startRange;
   }
@@ -108,9 +112,11 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
     int endStart = decodeMiddle(row, startGuardRange, result);
     int[] endRange = decodeEnd(row, endStart);
 
-    // Check for whitespace after the pattern -- 150% of size of end pattern
+    // Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
+    // spec might want more whitespace, but in practice this is the maximum we can count on.
     int end = endRange[1];
-    if (!row.isRange(end, Math.min(row.getSize(), end + (3 * (end - endRange[0])) / 2), false)) {
+    int quietEnd = end + (end - endRange[0]);
+    if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
       throw new ReaderException("Pattern not followed by whitespace");
     }
 
index 4e39d01..d1e0abb 100644 (file)
@@ -29,9 +29,9 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractNegativeBlackB
 
   public FalsePositivesBlackBoxTestCase() {
     super(new File("test/data/blackbox/falsepositives"));
-    addTest(1, 0.0f);
-    addTest(1, 90.0f);
-    addTest(2, 180.0f);
+    addTest(2, 0.0f);
+    addTest(0, 90.0f);
+    addTest(0, 180.0f);
     addTest(0, 270.0f);
   }
 
index 35b019b..ae165f0 100644 (file)
@@ -29,10 +29,10 @@ public final class PartialBlackBoxTestCase extends AbstractNegativeBlackBoxTestC
 
   public PartialBlackBoxTestCase() {
     super(new File("test/data/blackbox/partial"));
-    addTest(18, 0.0f);
-    addTest(19, 90.0f);
-    addTest(19, 180.0f);
-    addTest(18, 270.0f);
+    addTest(0, 0.0f);
+    addTest(1, 90.0f);
+    addTest(1, 180.0f);
+    addTest(0, 270.0f);
   }
 
 }
index ae72c31..c0f2c09 100644 (file)
@@ -30,7 +30,7 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
   public EAN13BlackBox1TestCase() {
     super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13);
     addTest(28, 31, 0.0f);
-    addTest(25, 31, 180.0f);
+    addTest(27, 31, 180.0f);
   }
 
 }
\ No newline at end of file
index 48663bd..9bac32d 100644 (file)
@@ -29,8 +29,8 @@ public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase {
 
   public UPCABlackBox1TestCase() {
     super(new File("test/data/blackbox/upca-1"), new MultiFormatReader(), BarcodeFormat.UPC_A);
-    addTest(15, 17, 0.0f);
-    addTest(16, 19, 180.0f);
+    addTest(15, 16, 0.0f);
+    addTest(15, 19, 180.0f);
   }
 
 }
\ No newline at end of file
index 60c387b..417fcbb 100644 (file)
@@ -29,7 +29,7 @@ public final class UPCABlackBox2TestCase extends AbstractBlackBoxTestCase {
 
   public UPCABlackBox2TestCase() {
     super(new File("test/data/blackbox/upca-2"), new MultiFormatReader(), BarcodeFormat.UPC_A);
-    addTest(26, 35, 0.0f);
+    addTest(25, 35, 0.0f);
     addTest(25, 35, 180.0f);
   }
 
index 699e02a..5232d66 100644 (file)
@@ -29,8 +29,8 @@ public final class UPCABlackBox4TestCase extends AbstractBlackBoxTestCase {
 
   public UPCABlackBox4TestCase() {
     super(new File("test/data/blackbox/upca-4"), new MultiFormatReader(), BarcodeFormat.UPC_A);
-    addTest(8, 10, 0.0f);
-    addTest(7, 12, 180.0f);
+    addTest(8, 13, 0.0f);
+    addTest(8, 12, 180.0f);
   }
 
 }
index 7c96737..37a229e 100644 (file)
@@ -29,8 +29,8 @@ public final class UPCEBlackBox2TestCase extends AbstractBlackBoxTestCase {
 
   public UPCEBlackBox2TestCase() {
     super(new File("test/data/blackbox/upce-2"), new MultiFormatReader(), BarcodeFormat.UPC_E);
-    addTest(24, 34, 0.0f);
-    addTest(26, 34, 180.0f);
+    addTest(30, 35, 0.0f);
+    addTest(29, 35, 180.0f);
   }
 
 }
index ee0e31a..011a506 100644 (file)
@@ -29,8 +29,8 @@ public final class UPCEBlackBox3ReflectiveTestCase extends AbstractBlackBoxTestC
 
   public UPCEBlackBox3ReflectiveTestCase() {
     super(new File("test/data/blackbox/upce-3"), new MultiFormatReader(), BarcodeFormat.UPC_E);
-    addTest(0, 0, 0.0f);
-    addTest(0, 0, 180.0f);
+    addTest(4, 8, 0.0f);
+    addTest(4, 8, 180.0f);
   }
 
 }