- Got the DataMatrix decoder compiling again with a quick bandaid.
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 29 Jun 2009 15:49:42 +0000 (15:49 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 29 Jun 2009 15:49:42 +0000 (15:49 +0000)
- Fixed two bugs in the LocalBlockBinarizer sharpening routine. It can now decode 2132 images in our blackbox tests, compared to 2103 using the global histogram approach.
- Added the PDF 417 blackbox test to AllPositiveBlackBoxTester, and allowed it to complete even if the tests fail.

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

core/src/com/google/zxing/common/LocalBlockBinarizer.java
core/src/com/google/zxing/pdf417/detector/Detector.java
core/test/src/com/google/zxing/AllPositiveBlackBoxTester.java
core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java

index 55be9b8..93fc031 100644 (file)
@@ -27,6 +27,8 @@ import com.google.zxing.LuminanceSource;
  * However it tends to produce artifacts on lower frequency images and is therefore not
  * a good general purpose binarizer for uses outside ZXing.
  *
+ * NOTE: This class is still experimental and may not be ready for prime time yet.
+ *
  * @author dswitkin@google.com (Daniel Switkin)
  */
 public final class LocalBlockBinarizer extends Binarizer {
@@ -37,11 +39,13 @@ public final class LocalBlockBinarizer extends Binarizer {
     super(source);
   }
 
+  // TODO: Consider a different strategy for 1D Readers.
   public BitArray getBlackRow(int y, BitArray row) {
     binarizeEntireImage();
     return matrix.getRow(y, row);
   }
 
+  // TODO: If getBlackRow() calculates its own values, removing sharpening here.
   public BitMatrix getBlackMatrix() {
     binarizeEntireImage();
     return matrix;
@@ -152,7 +156,14 @@ public final class LocalBlockBinarizer extends Binarizer {
       int center = luminances[offset + 1] & 0xff;
       for (int x = 1; x < width - 1; x++) {
         int right = luminances[offset + x + 1] & 0xff;
-        luminances[x] = (byte)(((center << 2) - left - right) >> 1);
+        int pixel = ((center << 2) - left - right) >> 1;
+        // Must clamp values to 0..255 so they will fit in a byte.
+        if (pixel > 255) {
+          pixel = 255;
+        } else if (pixel < 0) {
+          pixel = 0;
+        }
+        luminances[offset + x] = (byte)pixel;
         left = center;
         center = right;
       }
index 8bc4eb8..53edd41 100644 (file)
@@ -337,7 +337,10 @@ public final class Detector {
     // modules, but the
     // very corners. So there is no 0.5f here; 0.0f is right.
     GridSampler sampler = GridSampler.getInstance();
-    return sampler.sampleGrid(image, dimension, 0.0f, // p1ToX
+
+    // FIXME: Temporary fix calling getBlackMatrix() inline here. It should be called once
+    // and the result matrix passed down into sampleGrid() and throughout the reader.
+    return sampler.sampleGrid(image.getBlackMatrix(), dimension, 0.0f, // p1ToX
         0.0f, // p1ToY
         dimension, // p2ToX
         0.0f, // p2ToY
index 53c9c49..e72a370 100644 (file)
@@ -39,6 +39,7 @@ import com.google.zxing.oned.UPCABlackBox4TestCase;
 import com.google.zxing.oned.UPCEBlackBox1TestCase;
 import com.google.zxing.oned.UPCEBlackBox2TestCase;
 import com.google.zxing.oned.UPCEBlackBox3ReflectiveTestCase;
+import com.google.zxing.pdf417.PDF417BlackBox1TestCase;
 import com.google.zxing.qrcode.QRCodeBlackBox1TestCase;
 import com.google.zxing.qrcode.QRCodeBlackBox2TestCase;
 import com.google.zxing.qrcode.QRCodeBlackBox3TestCase;
@@ -81,6 +82,7 @@ public final class AllPositiveBlackBoxTester {
     new UPCEBlackBox1TestCase(),
     new UPCEBlackBox2TestCase(),
     new UPCEBlackBox3ReflectiveTestCase(),
+    new PDF417BlackBox1TestCase(),
     new QRCodeBlackBox1TestCase(),
     new QRCodeBlackBox2TestCase(),
     new QRCodeBlackBox3TestCase(),
@@ -156,7 +158,7 @@ public final class AllPositiveBlackBoxTester {
     AbstractBlackBoxTestCase.SummaryResults results = new AbstractBlackBoxTestCase.SummaryResults();
 
     for (int x = 0; x < TESTS.length; x++) {
-      results.add(TESTS[x].testBlackBoxCountingResults());
+      results.add(TESTS[x].testBlackBoxCountingResults(false));
     }
 
     // This threaded version can't be used yet because BlackPointEstimator (and possibly other code)
index e24f5fb..19dc156 100644 (file)
@@ -160,10 +160,10 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
   // This workaround is used because AbstractNegativeBlackBoxTestCase overrides this method but does
   // not return SummaryResults.
   public void testBlackBox() throws IOException {
-    testBlackBoxCountingResults();
+    testBlackBoxCountingResults(true);
   }
 
-  public SummaryResults testBlackBoxCountingResults() throws IOException {
+  public SummaryResults testBlackBoxCountingResults(boolean assertOnFailure) throws IOException {
     assertFalse(testResults.isEmpty());
 
     File[] imageFiles = getImageFiles();
@@ -218,13 +218,15 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
     }
 
     // Then run through again and assert if any failed
-    for (int x = 0; x < testCount; x++) {
-      assertTrue("Rotation " + testResults.get(x).getRotation() +
-          " degrees: Too many images failed",
-          passedCounts[x] >= testResults.get(x).getMustPassCount());
-      assertTrue("Try harder, Rotation " + testResults.get(x).getRotation() +
-          " degrees: Too many images failed",
-          tryHarderCounts[x] >= testResults.get(x).getTryHarderCount());
+    if (assertOnFailure) {
+      for (int x = 0; x < testCount; x++) {
+        assertTrue("Rotation " + testResults.get(x).getRotation() +
+            " degrees: Too many images failed",
+            passedCounts[x] >= testResults.get(x).getMustPassCount());
+        assertTrue("Try harder, Rotation " + testResults.get(x).getRotation() +
+            " degrees: Too many images failed",
+            tryHarderCounts[x] >= testResults.get(x).getTryHarderCount());
+      }
     }
     return new SummaryResults(totalFound, totalMustPass, totalTests);
   }