mirror of
https://github.com/zxing/zxing.git
synced 2024-11-13 22:44:09 -08:00
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:
parent
09ce5db11d
commit
8cb804ec9e
|
@ -35,7 +35,7 @@ import java.util.Hashtable;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractUPCEANReader extends AbstractOneDReader implements UPCEANReader {
|
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);
|
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);
|
startRange = findGuardPattern(row, nextStart, false, START_END_PATTERN);
|
||||||
int start = startRange[0];
|
int start = startRange[0];
|
||||||
nextStart = startRange[1];
|
nextStart = startRange[1];
|
||||||
// As a check, we want to see some white in front of this "start pattern",
|
// Make sure there is a quiet zone at least as big as the start pattern before the barcode. If
|
||||||
// maybe as wide as the 150% of the start pattern itself?
|
// this check would run off the left edge of the image, do not accept this barcode, as it is
|
||||||
foundStart = row.isRange(Math.max(0, start - (3 * (nextStart - start)) / 2), start, false);
|
// very likely to be a false positive.
|
||||||
|
int quietStart = start - (nextStart - start);
|
||||||
|
if (quietStart >= 0) {
|
||||||
|
foundStart = row.isRange(quietStart, start, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return startRange;
|
return startRange;
|
||||||
}
|
}
|
||||||
|
@ -108,9 +112,11 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
|
||||||
int endStart = decodeMiddle(row, startGuardRange, result);
|
int endStart = decodeMiddle(row, startGuardRange, result);
|
||||||
int[] endRange = decodeEnd(row, endStart);
|
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];
|
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");
|
throw new ReaderException("Pattern not followed by whitespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractNegativeBlackB
|
||||||
|
|
||||||
public FalsePositivesBlackBoxTestCase() {
|
public FalsePositivesBlackBoxTestCase() {
|
||||||
super(new File("test/data/blackbox/falsepositives"));
|
super(new File("test/data/blackbox/falsepositives"));
|
||||||
addTest(1, 0.0f);
|
addTest(2, 0.0f);
|
||||||
addTest(1, 90.0f);
|
addTest(0, 90.0f);
|
||||||
addTest(2, 180.0f);
|
addTest(0, 180.0f);
|
||||||
addTest(0, 270.0f);
|
addTest(0, 270.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ public final class PartialBlackBoxTestCase extends AbstractNegativeBlackBoxTestC
|
||||||
|
|
||||||
public PartialBlackBoxTestCase() {
|
public PartialBlackBoxTestCase() {
|
||||||
super(new File("test/data/blackbox/partial"));
|
super(new File("test/data/blackbox/partial"));
|
||||||
addTest(18, 0.0f);
|
addTest(0, 0.0f);
|
||||||
addTest(19, 90.0f);
|
addTest(1, 90.0f);
|
||||||
addTest(19, 180.0f);
|
addTest(1, 180.0f);
|
||||||
addTest(18, 270.0f);
|
addTest(0, 270.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||||
public EAN13BlackBox1TestCase() {
|
public EAN13BlackBox1TestCase() {
|
||||||
super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13);
|
super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13);
|
||||||
addTest(28, 31, 0.0f);
|
addTest(28, 31, 0.0f);
|
||||||
addTest(25, 31, 180.0f);
|
addTest(27, 31, 180.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -29,8 +29,8 @@ public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase {
|
||||||
|
|
||||||
public UPCABlackBox1TestCase() {
|
public UPCABlackBox1TestCase() {
|
||||||
super(new File("test/data/blackbox/upca-1"), new MultiFormatReader(), BarcodeFormat.UPC_A);
|
super(new File("test/data/blackbox/upca-1"), new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||||
addTest(15, 17, 0.0f);
|
addTest(15, 16, 0.0f);
|
||||||
addTest(16, 19, 180.0f);
|
addTest(15, 19, 180.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -29,7 +29,7 @@ public final class UPCABlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||||
|
|
||||||
public UPCABlackBox2TestCase() {
|
public UPCABlackBox2TestCase() {
|
||||||
super(new File("test/data/blackbox/upca-2"), new MultiFormatReader(), BarcodeFormat.UPC_A);
|
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);
|
addTest(25, 35, 180.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ public final class UPCABlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
|
|
||||||
public UPCABlackBox4TestCase() {
|
public UPCABlackBox4TestCase() {
|
||||||
super(new File("test/data/blackbox/upca-4"), new MultiFormatReader(), BarcodeFormat.UPC_A);
|
super(new File("test/data/blackbox/upca-4"), new MultiFormatReader(), BarcodeFormat.UPC_A);
|
||||||
addTest(8, 10, 0.0f);
|
addTest(8, 13, 0.0f);
|
||||||
addTest(7, 12, 180.0f);
|
addTest(8, 12, 180.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public final class UPCEBlackBox2TestCase extends AbstractBlackBoxTestCase {
|
||||||
|
|
||||||
public UPCEBlackBox2TestCase() {
|
public UPCEBlackBox2TestCase() {
|
||||||
super(new File("test/data/blackbox/upce-2"), new MultiFormatReader(), BarcodeFormat.UPC_E);
|
super(new File("test/data/blackbox/upce-2"), new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||||
addTest(24, 34, 0.0f);
|
addTest(30, 35, 0.0f);
|
||||||
addTest(26, 34, 180.0f);
|
addTest(29, 35, 180.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public final class UPCEBlackBox3ReflectiveTestCase extends AbstractBlackBoxTestC
|
||||||
|
|
||||||
public UPCEBlackBox3ReflectiveTestCase() {
|
public UPCEBlackBox3ReflectiveTestCase() {
|
||||||
super(new File("test/data/blackbox/upce-3"), new MultiFormatReader(), BarcodeFormat.UPC_E);
|
super(new File("test/data/blackbox/upce-3"), new MultiFormatReader(), BarcodeFormat.UPC_E);
|
||||||
addTest(0, 0, 0.0f);
|
addTest(4, 8, 0.0f);
|
||||||
addTest(0, 0, 180.0f);
|
addTest(4, 8, 180.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue