Made a change to 1D decoding which looks for 100% instead of 150% of the start and end patterns when searching for quiet zones, but in exchange for that reduction, we reject rows whose quiet zones would run off either edge of the image.

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: https://zxing.googlecode.com/svn/trunk@620 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-10-15 19:47:34 +00:00
parent 09ce5db11d
commit 8cb804ec9e
9 changed files with 29 additions and 23 deletions

View 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");
}

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

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

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

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

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

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

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

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