Fix bad logic black point estimator, improving threshold estimation performance (and adjust some == to .equals())

git-svn-id: https://zxing.googlecode.com/svn/trunk@417 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-06-11 19:59:38 +00:00
parent 88afca0842
commit f5b58916c1
4 changed files with 10 additions and 7 deletions

View file

@ -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++) {

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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++) {