From: srowen Date: Wed, 7 Nov 2007 19:18:50 +0000 (+0000) Subject: Adjust tolerance of method that decides whether a finder/alignment pattern has been... X-Git-Url: http://git.rot13.org/?p=zxing.git;a=commitdiff_plain;h=6980903e85309b4f167d21206d86b467cc6ef4f9 Adjust tolerance of method that decides whether a finder/alignment pattern has been crossed so that it passes on low resolution images more correctly -- just a matter of resorting to some floating point math. git-svn-id: http://zxing.googlecode.com/svn/trunk@18 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java index b4e35502..e68d3a18 100644 --- a/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java @@ -164,8 +164,9 @@ final class AlignmentPatternFinder { */ private boolean foundPatternCross(int[] stateCount) { float moduleSize = this.moduleSize; + float maxVariance = moduleSize / 2.5f; for (int i = 0; i < 3; i++) { - if (2.0f * Math.abs(moduleSize - stateCount[i]) >= moduleSize) { + if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) { return false; } } diff --git a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java index 4ef3d58c..0c8a91e7 100755 --- a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java @@ -178,13 +178,14 @@ final class FinderPatternFinder { if (totalModuleSize < 7) { return false; } - int moduleSize = totalModuleSize / 7; - // Allow less than 50% deviance from 1-1-3-1-1 pattern - return Math.abs(moduleSize - stateCount[0]) << 1 <= moduleSize && - Math.abs(moduleSize - stateCount[1]) << 1 <= moduleSize && - Math.abs(3 * moduleSize - stateCount[2]) << 1 <= 3 * moduleSize && - Math.abs(moduleSize - stateCount[3]) << 1 <= moduleSize && - Math.abs(moduleSize - stateCount[4]) << 1 <= moduleSize; + float moduleSize = (float) totalModuleSize / 7.0f; + float maxVariance = moduleSize / 2.5f; + // Allow less than 40% variance from 1-1-3-1-1 proportions + return Math.abs(moduleSize - stateCount[0]) < maxVariance && + Math.abs(moduleSize - stateCount[1]) < maxVariance && + Math.abs(3.0f * moduleSize - stateCount[2]) < 3.0f * maxVariance && + Math.abs(moduleSize - stateCount[3]) < maxVariance && + Math.abs(moduleSize - stateCount[4]) < maxVariance; } /**