@@ -58,7 +58,8 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
5858 $ tryHarder = $ hints != null && array_key_exists ('TRY_HARDER ' , $ hints ) && $ hints ['TRY_HARDER ' ];
5959 $ pureBarcode = $ hints != null && array_key_exists ('PURE_BARCODE ' , $ hints ) && $ hints ['PURE_BARCODE ' ];
6060 $ nrOfRowsSkippable = $ hints != null && array_key_exists ('NR_ALLOW_SKIP_ROWS ' , $ hints ) ? $ hints ['NR_ALLOW_SKIP_ROWS ' ] : ($ tryHarder ? 0 : null );
61- $ allowedDeviation = $ hints != null && array_key_exists ('ALLOWED_DEVIATION ' , $ hints ) ? $ hints ['ALLOWED_DEVIATION ' ] : null ;
61+ $ allowedDeviation = $ hints != null && array_key_exists ('ALLOWED_DEVIATION ' , $ hints ) ? $ hints ['ALLOWED_DEVIATION ' ] : 0.05 ;
62+ $ maxVariance = $ hints != null && array_key_exists ('MAX_VARIANCE ' , $ hints ) ? $ hints ['MAX_VARIANCE ' ] : 0.5 ;
6263 $ maxI = $ this ->image ->getHeight ();
6364 $ maxJ = $ this ->image ->getWidth ();
6465 // We are looking for black/white/black/white/black modules in
@@ -93,7 +94,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
9394 } else { // White pixel
9495 if (($ currentState & 1 ) == 0 ) { // Counting black pixels
9596 if ($ currentState == 4 ) { // A winner?
96- if (self ::foundPatternCross ($ stateCount )) { // Yes
97+ if (self ::foundPatternCross ($ stateCount, $ maxVariance )) { // Yes
9798 $ confirmed = $ this ->handlePossibleCenter ($ stateCount , $ i , $ j , $ pureBarcode );
9899 if ($ confirmed ) {
99100 // Start examining every other line. Checking each line turned out to be too
@@ -148,7 +149,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
148149 }
149150 }
150151 }
151- if (self ::foundPatternCross ($ stateCount )) {
152+ if (self ::foundPatternCross ($ stateCount, $ maxVariance )) {
152153 $ confirmed = $ this ->handlePossibleCenter ($ stateCount , $ i , $ maxJ , $ pureBarcode );
153154 if ($ confirmed ) {
154155 $ iSkip = $ stateCount [0 ];
@@ -174,7 +175,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
174175 *
175176 * @psalm-param array<0|positive-int, int> $stateCount
176177 */
177- protected static function foundPatternCross (array $ stateCount ): bool
178+ protected static function foundPatternCross (array $ stateCount, float $ maxVariance = 0.5 ): bool
178179 {
179180 $ totalModuleSize = 0 ;
180181 for ($ i = 0 ; $ i < 5 ; $ i ++) {
@@ -188,7 +189,7 @@ protected static function foundPatternCross(array $stateCount): bool
188189 return false ;
189190 }
190191 $ moduleSize = $ totalModuleSize / 7.0 ;
191- $ maxVariance = $ moduleSize / 2.0 ;
192+ $ maxVariance = $ moduleSize * $ maxVariance ;
192193
193194 // Allow less than 50% variance from 1-1-3-1-1 proportions
194195 return
0 commit comments