@@ -58,6 +58,7 @@ 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 ;
6162 $ maxI = $ this ->image ->getHeight ();
6263 $ maxJ = $ this ->image ->getWidth ();
6364 // We are looking for black/white/black/white/black modules in
@@ -99,7 +100,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
99100 // expensive and didn't improve performance.
100101 $ iSkip = 3 ;
101102 if ($ this ->hasSkipped ) {
102- $ done = $ this ->haveMultiplyConfirmedCenters ();
103+ $ done = $ this ->haveMultiplyConfirmedCenters ($ allowedDeviation );
103104 } else {
104105 $ rowSkip = $ nrOfRowsSkippable === null ? $ this ->findRowSkip () : $ nrOfRowsSkippable ;
105106 if ($ rowSkip > $ stateCount [2 ]) {
@@ -153,7 +154,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
153154 $ iSkip = $ stateCount [0 ];
154155 if ($ this ->hasSkipped ) {
155156 // Found a third one
156- $ done = $ this ->haveMultiplyConfirmedCenters ();
157+ $ done = $ this ->haveMultiplyConfirmedCenters ($ allowedDeviation );
157158 }
158159 }
159160 }
@@ -537,7 +538,7 @@ private function crossCheckDiagonal(int $startI, int $centerJ, $maxCount, int|fl
537538 /**
538539 * @return bool iff we have found at least 3 finder patterns that have been detected at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the candidates is "pretty similar"
539540 */
540- private function haveMultiplyConfirmedCenters (): bool
541+ private function haveMultiplyConfirmedCenters (? float $ allowedDeviation = 0.05 ): bool
541542 {
542543 $ confirmedCount = 0 ;
543544 $ totalModuleSize = 0.0 ;
@@ -561,7 +562,7 @@ private function haveMultiplyConfirmedCenters(): bool
561562 $ totalDeviation += abs ($ pattern ->getEstimatedModuleSize () - $ average );
562563 }
563564
564- return $ totalDeviation <= 0.05 * $ totalModuleSize ;
565+ return $ totalDeviation <= $ allowedDeviation * $ totalModuleSize ;
565566 }
566567
567568 /**
@@ -609,7 +610,7 @@ private function selectBestPatterns()
609610 $ startSize = count ($ this ->possibleCenters );
610611 if ($ startSize < 3 ) {
611612 // Couldn't find enough finder patterns
612- throw new NotFoundException ("Could not find 3 finder patterns " );
613+ throw new NotFoundException ("Could not find 3 finder patterns ( $ startSize found) " );
613614 }
614615
615616 // Filter outlier possibilities whose module size is too different
0 commit comments