From 63f219b54ddaff17b704a67db1e319b846cef253 Mon Sep 17 00:00:00 2001 From: dswitkin Date: Mon, 29 Jun 2009 15:49:42 +0000 Subject: [PATCH] - Got the DataMatrix decoder compiling again with a quick bandaid. - 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 --- .../zxing/common/LocalBlockBinarizer.java | 13 +++++++++++- .../zxing/pdf417/detector/Detector.java | 5 ++++- .../zxing/AllPositiveBlackBoxTester.java | 4 +++- .../common/AbstractBlackBoxTestCase.java | 20 ++++++++++--------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/core/src/com/google/zxing/common/LocalBlockBinarizer.java b/core/src/com/google/zxing/common/LocalBlockBinarizer.java index 55be9b8b..93fc0311 100644 --- a/core/src/com/google/zxing/common/LocalBlockBinarizer.java +++ b/core/src/com/google/zxing/common/LocalBlockBinarizer.java @@ -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; } diff --git a/core/src/com/google/zxing/pdf417/detector/Detector.java b/core/src/com/google/zxing/pdf417/detector/Detector.java index 8bc4eb84..53edd41b 100644 --- a/core/src/com/google/zxing/pdf417/detector/Detector.java +++ b/core/src/com/google/zxing/pdf417/detector/Detector.java @@ -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 diff --git a/core/test/src/com/google/zxing/AllPositiveBlackBoxTester.java b/core/test/src/com/google/zxing/AllPositiveBlackBoxTester.java index 53c9c49a..e72a370b 100644 --- a/core/test/src/com/google/zxing/AllPositiveBlackBoxTester.java +++ b/core/test/src/com/google/zxing/AllPositiveBlackBoxTester.java @@ -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) diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index e24f5fba..19dc1563 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -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); } -- 2.20.1