Skip to content

Commit 641da36

Browse files
authored
Merge pull request #224 from AlessandroFlorio/detectPrintDefects
match badly-printed QR codes
2 parents 4f3a13f + a48bc1d commit 641da36

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/zxing/zxing/qrcode/detector/QRFinderPatternFinder.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,24 @@ bool FinderPatternFinder::foundPatternCross(int *stateCount)
8787
int moduleSize = (totalModuleSize << 8) / 7;
8888
int maxVariance = moduleSize / 2;
8989
// Allow less than 50% variance from 1-1-3-1-1 proportions
90-
return ::abs(moduleSize - (stateCount[0] << 8)) < maxVariance &&
90+
if ( ::abs(moduleSize - (stateCount[0] << 8)) < maxVariance &&
9191
::abs(moduleSize - (stateCount[1] << 8)) < maxVariance &&
9292
::abs(3.0f * moduleSize - (stateCount[2] << 8)) < 3 * maxVariance &&
9393
::abs(moduleSize - (stateCount[3] << 8)) < maxVariance &&
94-
::abs(moduleSize - (stateCount[4] << 8)) < maxVariance;
94+
::abs(moduleSize - (stateCount[4] << 8)) < maxVariance
95+
) {
96+
return true;
97+
}
98+
99+
// Proportions are not matched by the pattern. However, a bad print or a blurred frame
100+
// may lead to a false negative. Try to check whether there is a valid center and the
101+
// two extremities are of similar size, with blacks and whites having matching widths.
102+
103+
return ::abs(3.0f * moduleSize - (stateCount[2] << 8)) < 3 * maxVariance && // center is 3/7 +- variance
104+
::abs(2.0f * moduleSize - ((stateCount[0] + stateCount[1]) << 8)) < 2 * maxVariance && // left/top is 2/7 +- variance
105+
::abs(2.0f * moduleSize - ((stateCount[3] + stateCount[4]) << 8)) < 2 * maxVariance && // right/bottom is 2/7 +- variance
106+
(::abs(stateCount[0] - stateCount[4]) << 8) < maxVariance && // difference between first and last black is < variance
107+
(::abs(stateCount[1] - stateCount[3]) << 8) < maxVariance; // difference between whites is < variance
95108
}
96109

97110
float FinderPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal)

0 commit comments

Comments
 (0)