@@ -87,11 +87,24 @@ bool FinderPatternFinder::foundPatternCross(int *stateCount)
87
87
int moduleSize = (totalModuleSize << 8 ) / 7 ;
88
88
int maxVariance = moduleSize / 2 ;
89
89
// 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 &&
91
91
::abs (moduleSize - (stateCount[1 ] << 8 )) < maxVariance &&
92
92
::abs(3 .0f * moduleSize - (stateCount[2 ] << 8 )) < 3 * maxVariance &&
93
93
::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
95
108
}
96
109
97
110
float FinderPatternFinder::crossCheckVertical (size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal)
0 commit comments