@@ -58,6 +58,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
58
58
$ tryHarder = $ hints != null && array_key_exists ('TRY_HARDER ' , $ hints ) && $ hints ['TRY_HARDER ' ];
59
59
$ pureBarcode = $ hints != null && array_key_exists ('PURE_BARCODE ' , $ hints ) && $ hints ['PURE_BARCODE ' ];
60
60
$ 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
62
$ maxI = $ this ->image ->getHeight ();
62
63
$ maxJ = $ this ->image ->getWidth ();
63
64
// 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
99
100
// expensive and didn't improve performance.
100
101
$ iSkip = 3 ;
101
102
if ($ this ->hasSkipped ) {
102
- $ done = $ this ->haveMultiplyConfirmedCenters ();
103
+ $ done = $ this ->haveMultiplyConfirmedCenters ($ allowedDeviation );
103
104
} else {
104
105
$ rowSkip = $ nrOfRowsSkippable === null ? $ this ->findRowSkip () : $ nrOfRowsSkippable ;
105
106
if ($ rowSkip > $ stateCount [2 ]) {
@@ -153,7 +154,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
153
154
$ iSkip = $ stateCount [0 ];
154
155
if ($ this ->hasSkipped ) {
155
156
// Found a third one
156
- $ done = $ this ->haveMultiplyConfirmedCenters ();
157
+ $ done = $ this ->haveMultiplyConfirmedCenters ($ allowedDeviation );
157
158
}
158
159
}
159
160
}
@@ -537,7 +538,7 @@ private function crossCheckDiagonal(int $startI, int $centerJ, $maxCount, int|fl
537
538
/**
538
539
* @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"
539
540
*/
540
- private function haveMultiplyConfirmedCenters (): bool
541
+ private function haveMultiplyConfirmedCenters (? float $ allowedDeviation = 0.05 ): bool
541
542
{
542
543
$ confirmedCount = 0 ;
543
544
$ totalModuleSize = 0.0 ;
@@ -561,7 +562,7 @@ private function haveMultiplyConfirmedCenters(): bool
561
562
$ totalDeviation += abs ($ pattern ->getEstimatedModuleSize () - $ average );
562
563
}
563
564
564
- return $ totalDeviation <= 0.05 * $ totalModuleSize ;
565
+ return $ totalDeviation <= $ allowedDeviation * $ totalModuleSize ;
565
566
}
566
567
567
568
/**
@@ -609,7 +610,7 @@ private function selectBestPatterns()
609
610
$ startSize = count ($ this ->possibleCenters );
610
611
if ($ startSize < 3 ) {
611
612
// 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) " );
613
614
}
614
615
615
616
// Filter outlier possibilities whose module size is too different
0 commit comments