From 256f3125fd9ffa08e0c9e347071ef5038e9c9a28 Mon Sep 17 00:00:00 2001 From: srowen Date: Thu, 8 May 2008 15:12:44 +0000 Subject: [PATCH] Detector is now a little more skeptical once it has found 3 confirmed finder patterns -- one may be a false positive, so it also checks to see if the estimated module sizes are "pretty similar". If not, keeps looking. git-svn-id: http://zxing.googlecode.com/svn/trunk@394 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../qrcode/detector/FinderPatternFinder.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java index 029be72d..10c0708b 100755 --- a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java @@ -419,19 +419,34 @@ final class FinderPatternFinder { /** * @return true iff we have found at least 3 finder patterns that have been detected - * at least {@link #CENTER_QUORUM} times each + * at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the + * candidates is "pretty similar" */ private boolean haveMulitplyConfirmedCenters() { - int count = 0; + int confirmedCount = 0; + float totalModuleSize = 0.0f; int max = possibleCenters.size(); for (int i = 0; i < max; i++) { - if (((FinderPattern) possibleCenters.elementAt(i)).getCount() >= CENTER_QUORUM) { - if (++count == 3) { - return true; - } + FinderPattern pattern = (FinderPattern) possibleCenters.elementAt(i); + if (pattern.getCount() >= CENTER_QUORUM) { + confirmedCount++; + totalModuleSize += pattern.getEstimatedModuleSize(); } } - return false; + if (confirmedCount < 3) { + return false; + } + // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive" + // and that we need to keep looking. We detect this by asking if the estimated module sizes + // vary too much. We arbitrarily say that when the total deviation from average exceeds + // 15% of the total module size estimates, it's too much. + float average = totalModuleSize / max; + float totalDeviation = 0.0f; + for (int i = 0; i < max; i++) { + FinderPattern pattern = (FinderPattern) possibleCenters.elementAt(i); + totalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average); + } + return totalDeviation <= 0.15f * totalModuleSize; } /** -- 2.20.1