Fix pretty clear bug on Code 128 and 39 readers: reject empty barcodes as a false positive.

git-svn-id: https://zxing.googlecode.com/svn/trunk@440 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-06-18 21:56:30 +00:00
parent 593128df02
commit 2f9e5ca32b
3 changed files with 16 additions and 0 deletions

View file

@ -405,6 +405,12 @@ public final class Code128Reader extends AbstractOneDReader {
} }
String resultString = result.toString(); String resultString = result.toString();
if (resultString.length() == 0) {
// Almost surely a false positive
throw new ReaderException("Empty barcode found; assuming a false positive");
}
float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f; float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
float right = (float) (nextStart + lastStart) / 2.0f; float right = (float) (nextStart + lastStart) / 2.0f;
return new Result( return new Result(

View file

@ -138,6 +138,12 @@ public final class Code39Reader extends AbstractOneDReader {
if (extendedMode) { if (extendedMode) {
resultString = decodeExtended(resultString); resultString = decodeExtended(resultString);
} }
if (resultString.length() == 0) {
// Almost surely a false positive
throw new ReaderException("Empty barcode found; assuming a false positive");
}
float left = (float) (start[1] + start[0]) / 2.0f; float left = (float) (start[1] + start[0]) / 2.0f;
float right = (float) (nextStart + lastStart) / 2.0f; float right = (float) (nextStart + lastStart) / 2.0f;
return new Result( return new Result(

View file

@ -42,6 +42,7 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractBlackBoxTestCa
super(new File("test/data/blackbox/falsepositives"), new MultiFormatReader(), null); super(new File("test/data/blackbox/falsepositives"), new MultiFormatReader(), null);
} }
@Override
public void testBlackBox() throws IOException { public void testBlackBox() throws IOException {
File[] imageFiles = getImageFiles(); File[] imageFiles = getImageFiles();
int falsePositives = 0; int falsePositives = 0;
@ -51,6 +52,9 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractBlackBoxTestCa
// Try all four rotations, since many of the test images don't have a notion of up, and we // Try all four rotations, since many of the test images don't have a notion of up, and we
// want to be as robust as possible. // want to be as robust as possible.
BufferedImage image = ImageIO.read(testImage); BufferedImage image = ImageIO.read(testImage);
if (image == null) {
throw new IOException("Could not read image: " + testImage);
}
for (int x = 0; x < 4; x++) { for (int x = 0; x < 4; x++) {
if (!checkForFalsePositives(image, x * 90.0f)) { if (!checkForFalsePositives(image, x * 90.0f)) {
falsePositives++; falsePositives++;