\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