From b44ebbc96fa5e565f66a785858637054258c56e6 Mon Sep 17 00:00:00 2001 From: srowen Date: Wed, 11 Jun 2008 19:59:38 +0000 Subject: [PATCH] Fix bad logic black point estimator, improving threshold estimation performance (and adjust some == to .equals()) git-svn-id: http://zxing.googlecode.com/svn/trunk@417 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/client/android/RGBMonochromeBitmapSource.java | 2 +- .../src/com/google/zxing/common/BlackPointEstimator.java | 9 ++++++--- .../com/google/zxing/oned/EAN13BlackBox1TestCase.java | 4 ++-- .../client/j2se/BufferedImageMonochromeBitmapSource.java | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/android/src/com/google/zxing/client/android/RGBMonochromeBitmapSource.java b/android/src/com/google/zxing/client/android/RGBMonochromeBitmapSource.java index d84a9209..f6bf98b6 100755 --- a/android/src/com/google/zxing/client/android/RGBMonochromeBitmapSource.java +++ b/android/src/com/google/zxing/client/android/RGBMonochromeBitmapSource.java @@ -63,7 +63,7 @@ final class RGBMonochromeBitmapSource implements MonochromeBitmapSource { // If the current decoder calculated the blackPoint based on one row, assume we're trying to // decode a 1D barcode, and apply some sharpening. // TODO: We may want to add a fifth parameter to request the amount of shapening to be done. - if (lastMethod == BlackPointEstimationMethod.ROW_SAMPLING) { + if (lastMethod.equals(BlackPointEstimationMethod.ROW_SAMPLING)) { int left = computeRGBLuminance(pixelRow[0]); int center = computeRGBLuminance(pixelRow[1]); for (int i = 1; i < getWidth - 1; i++) { diff --git a/core/src/com/google/zxing/common/BlackPointEstimator.java b/core/src/com/google/zxing/common/BlackPointEstimator.java index a40a8530..ecaf96c4 100644 --- a/core/src/com/google/zxing/common/BlackPointEstimator.java +++ b/core/src/com/google/zxing/common/BlackPointEstimator.java @@ -47,7 +47,7 @@ public final class BlackPointEstimator { public static int estimate(int[] histogram) throws ReaderException{ int numBuckets = histogram.length; - + int maxBucketCount = 0; // Find tallest peak in histogram int firstPeak = 0; int firstPeakSize = 0; @@ -56,6 +56,9 @@ public final class BlackPointEstimator { firstPeak = i; firstPeakSize = histogram[i]; } + if (histogram[i] > maxBucketCount) { + maxBucketCount = histogram[i]; + } } // Find second-tallest peak -- well, another peak that is tall and not @@ -84,7 +87,7 @@ public final class BlackPointEstimator { // Decoding the image/line is either pointless, or may in some cases lead to a false positive // for 1D formats, which are relatively lenient. // We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart" - if (secondPeak - firstPeak <= histogram.length >> 4) { + if (secondPeak - firstPeak <= numBuckets >> 4) { throw new ReaderException("Too little dynamic range in luminance"); } @@ -95,7 +98,7 @@ public final class BlackPointEstimator { int fromFirst = i - firstPeak; // Favor a "valley" that is not too close to either peak -- especially not the black peak -- // and that has a low value of course - int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]); + int score = fromFirst * fromFirst * (secondPeak - i) * (maxBucketCount - histogram[i]); if (score > bestValleyScore) { bestValley = i; bestValleyScore = score; diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java index 7e28d886..772cf7ad 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java @@ -29,8 +29,8 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase { public EAN13BlackBox1TestCase() { super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13); - addTest(25, 0.0f); - addTest(18, 180.0f); + addTest(26, 0.0f); + addTest(24, 180.0f); } } \ No newline at end of file diff --git a/javase/src/com/google/zxing/client/j2se/BufferedImageMonochromeBitmapSource.java b/javase/src/com/google/zxing/client/j2se/BufferedImageMonochromeBitmapSource.java index 77c0d5c5..e8396b46 100644 --- a/javase/src/com/google/zxing/client/j2se/BufferedImageMonochromeBitmapSource.java +++ b/javase/src/com/google/zxing/client/j2se/BufferedImageMonochromeBitmapSource.java @@ -120,7 +120,7 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm // If the current decoder calculated the blackPoint based on one row, assume we're trying to // decode a 1D barcode, and apply some sharpening. // TODO: We may want to add a fifth parameter to request the amount of shapening to be done. - if (lastMethod == BlackPointEstimationMethod.ROW_SAMPLING) { + if (lastMethod.equals(BlackPointEstimationMethod.ROW_SAMPLING)) { int left = computeRGBLuminance(pixelRow[0]); int center = computeRGBLuminance(pixelRow[1]); for (int i = 1; i < getWidth - 1; i++) { -- 2.20.1