Detector is now a little more skeptical once it has found 3 confirmed finder patterns...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 8 May 2008 15:12:44 +0000 (15:12 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 8 May 2008 15:12:44 +0000 (15:12 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@394 59b500cc-1b3d-0410-9834-0bbf25fbcc57

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

index 029be72..10c0708 100755 (executable)
@@ -419,19 +419,34 @@ final class FinderPatternFinder {
 \r
   /**\r
    * @return true iff we have found at least 3 finder patterns that have been detected\r
-   *         at least {@link #CENTER_QUORUM} times each\r
+   *         at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the\r
+   *         candidates is "pretty similar"\r
    */\r
   private boolean haveMulitplyConfirmedCenters() {\r
-    int count = 0;\r
+    int confirmedCount = 0;\r
+    float totalModuleSize = 0.0f;\r
     int max = possibleCenters.size();\r
     for (int i = 0; i < max; i++) {\r
-      if (((FinderPattern) possibleCenters.elementAt(i)).getCount() >= CENTER_QUORUM) {\r
-        if (++count == 3) {\r
-          return true;\r
-        }\r
+      FinderPattern pattern = (FinderPattern) possibleCenters.elementAt(i);\r
+      if (pattern.getCount() >= CENTER_QUORUM) {\r
+        confirmedCount++;\r
+        totalModuleSize += pattern.getEstimatedModuleSize();\r
       }\r
     }\r
-    return false;\r
+    if (confirmedCount < 3) {\r
+      return false;\r
+    }\r
+    // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive"\r
+    // and that we need to keep looking. We detect this by asking if the estimated module sizes\r
+    // vary too much. We arbitrarily say that when the total deviation from average exceeds\r
+    // 15% of the total module size estimates, it's too much.\r
+    float average = totalModuleSize / max;\r
+    float totalDeviation = 0.0f;\r
+    for (int i = 0; i < max; i++) {\r
+      FinderPattern pattern = (FinderPattern) possibleCenters.elementAt(i);\r
+      totalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average);\r
+    }\r
+    return totalDeviation <= 0.15f * totalModuleSize;\r
   }\r
 \r
   /**\r