mirror of
https://github.com/zxing/zxing.git
synced 2025-02-21 02:55:27 -08:00
Simple check in Code 39 reader to determine wide bars vary in width a lot, to cut out most false positives
git-svn-id: https://zxing.googlecode.com/svn/trunk@442 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
180e833b3e
commit
15f34edb52
|
@ -216,14 +216,30 @@ public final class Code39Reader extends AbstractOneDReader {
|
|||
}
|
||||
maxNarrowCounter = minCounter;
|
||||
wideCounters = 0;
|
||||
int totalWideCountersWidth = 0;
|
||||
int pattern = 0;
|
||||
for (int i = 0; i < numCounters; i++) {
|
||||
int counter = counters[i];
|
||||
if (counters[i] > maxNarrowCounter) {
|
||||
pattern |= 1 << (numCounters - 1 - i);
|
||||
wideCounters++;
|
||||
totalWideCountersWidth += counter;
|
||||
}
|
||||
}
|
||||
if (wideCounters == 3) {
|
||||
// Found 3 wide counters, but are they close enough in width?
|
||||
// We can perform a cheap, conservative check to see if any individual
|
||||
// counter is more than 1.5 times the average:
|
||||
for (int i = 0; i < numCounters && wideCounters > 0; i++) {
|
||||
int counter = counters[i];
|
||||
if (counters[i] > maxNarrowCounter) {
|
||||
wideCounters--;
|
||||
// totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
|
||||
if ((counter << 1) >= totalWideCountersWidth) {
|
||||
throw new ReaderException("Wide bars vary too much in width, rejecting");
|
||||
}
|
||||
}
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
} while (wideCounters > 3);
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.io.IOException;
|
|||
public final class FalsePositivesBlackBoxTestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
// This number should be reduced as we get better at rejecting false positives.
|
||||
private static final int FALSE_POSITIVES_ALLOWED = 23;
|
||||
private static final int FALSE_POSITIVES_ALLOWED = 15;
|
||||
|
||||
// Use the multiformat reader to evaluate all decoders in the system.
|
||||
public FalsePositivesBlackBoxTestCase() {
|
||||
|
|
Loading…
Reference in a new issue