Adjust tolerance of method that decides whether a finder/alignment pattern has been...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 7 Nov 2007 19:18:50 +0000 (19:18 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 7 Nov 2007 19:18:50 +0000 (19:18 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@18 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java
core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java

index b4e3550..e68d3a1 100644 (file)
@@ -164,8 +164,9 @@ final class AlignmentPatternFinder {
    */\r
   private boolean foundPatternCross(int[] stateCount) {\r
     float moduleSize = this.moduleSize;\r
+    float maxVariance = moduleSize / 2.5f;\r
     for (int i = 0; i < 3; i++) {\r
-      if (2.0f * Math.abs(moduleSize - stateCount[i]) >= moduleSize) {\r
+      if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) {\r
         return false;\r
       }\r
     }\r
index 4ef3d58..0c8a91e 100755 (executable)
@@ -178,13 +178,14 @@ final class FinderPatternFinder {
     if (totalModuleSize < 7) {\r
       return false;\r
     }\r
-    int moduleSize = totalModuleSize / 7;\r
-    // Allow less than 50% deviance from 1-1-3-1-1 pattern\r
-    return  Math.abs(moduleSize - stateCount[0]) << 1 <= moduleSize &&\r
-            Math.abs(moduleSize - stateCount[1]) << 1 <= moduleSize &&\r
-            Math.abs(3 * moduleSize - stateCount[2]) << 1 <= 3 * moduleSize &&\r
-            Math.abs(moduleSize - stateCount[3]) << 1 <= moduleSize &&\r
-            Math.abs(moduleSize - stateCount[4]) << 1 <= moduleSize;\r
+    float moduleSize = (float) totalModuleSize / 7.0f;\r
+    float maxVariance = moduleSize / 2.5f;\r
+    // Allow less than 40% variance from 1-1-3-1-1 proportions\r
+    return  Math.abs(moduleSize - stateCount[0]) < maxVariance &&\r
+            Math.abs(moduleSize - stateCount[1]) < maxVariance &&\r
+            Math.abs(3.0f * moduleSize - stateCount[2]) < 3.0f * maxVariance &&\r
+            Math.abs(moduleSize - stateCount[3]) < maxVariance &&\r
+            Math.abs(moduleSize - stateCount[4]) < maxVariance;\r
   }\r
 \r
   /**\r