function __construct($posX, $posY, $estimatedModuleSize) { parent::__construct($posX, $posY); $this->estimatedModuleSize = $estimatedModuleSize; }
final function find($hints) { /*final FinderPatternInfo find(Map<DecodeHintType,?> hints) throws NotFoundException {*/ $tryHarder = $hints != null && $hints['TRY_HARDER']; $pureBarcode = $hints != null && $hints['PURE_BARCODE']; $maxI = $this->image->getHeight(); $maxJ = $this->image->getWidth(); // We are looking for black/white/black/white/black modules in // 1:1:3:1:1 ratio; this tracks the number of such modules seen so far // Let's assume that the maximum version QR Code we support takes up 1/4 the height of the // image, and then account for the center being 3 modules in size. This gives the smallest // number of pixels the center could be, so skip this often. When trying harder, look for all // QR versions regardless of how dense they are. $iSkip = intval(3 * $maxI / (4 * self::$MAX_MODULES)); if ($iSkip < self::$MIN_SKIP || $tryHarder) { $iSkip = self::$MIN_SKIP; } $done = false; $stateCount = array(); for ($i = $iSkip - 1; $i < $maxI && !$done; $i += $iSkip) { // Get a row of black/white values $stateCount[0] = 0; $stateCount[1] = 0; $stateCount[2] = 0; $stateCount[3] = 0; $stateCount[4] = 0; $currentState = 0; for ($j = 0; $j < $maxJ; $j++) { if ($this->image->get($j, $i)) { // Black pixel if (($currentState & 1) == 1) { // Counting white pixels $currentState++; } $stateCount[$currentState]++; } else { // White pixel if (($currentState & 1) == 0) { // Counting black pixels if ($currentState == 4) { // A winner? if ($this->foundPatternCross($stateCount)) { // Yes $confirmed = $this->handlePossibleCenter($stateCount, $i, $j, $pureBarcode); if ($confirmed) { // Start examining every other line. Checking each line turned out to be too // expensive and didn't improve performance. $iSkip = 2; if ($this->hasSkipped) { $done = $this->haveMultiplyConfirmedCenters(); } else { $rowSkip = $this->findRowSkip(); if ($rowSkip > $stateCount[2]) { // Skip rows between row of lower confirmed center // and top of presumed third confirmed center // but back up a bit to get a full chance of detecting // it, entire width of center of finder pattern // Skip by rowSkip, but back off by $stateCount[2] (size of last center // of pattern we saw) to be conservative, and also back off by iSkip which // is about to be re-added $i += $rowSkip - $stateCount[2] - $iSkip; $j = $maxJ - 1; } } } else { $stateCount[0] = $stateCount[2]; $stateCount[1] = $stateCount[3]; $stateCount[2] = $stateCount[4]; $stateCount[3] = 1; $stateCount[4] = 0; $currentState = 3; continue; } // Clear state to start looking again $currentState = 0; $stateCount[0] = 0; $stateCount[1] = 0; $stateCount[2] = 0; $stateCount[3] = 0; $stateCount[4] = 0; } else { // No, shift counts back by two $stateCount[0] = $stateCount[2]; $stateCount[1] = $stateCount[3]; $stateCount[2] = $stateCount[4]; $stateCount[3] = 1; $stateCount[4] = 0; $currentState = 3; } } else { $stateCount[++$currentState]++; } } else { // Counting white pixels $stateCount[$currentState]++; } } } if ($this->foundPatternCross($stateCount)) { $confirmed = $this->handlePossibleCenter($stateCount, $i, $maxJ, $pureBarcode); if ($confirmed) { $iSkip = $stateCount[0]; if ($this->hasSkipped) { // Found a third one $done = $this->haveMultiplyConfirmedCenters(); } } } } $patternInfo = $this->selectBestPatterns(); $patternInfo = ResultPoint::orderBestPatterns($patternInfo); return new FinderPatternInfo($patternInfo); }
/** * <p>Computes the dimension (number of modules on a size) of the QR Code based on the position * of the finder patterns and estimated module size.</p> */ private static function computeDimension($topLeft, $topRight, $bottomLeft, $moduleSize) { $tltrCentersDimension = MathUtils::round(ResultPoint::distance($topLeft, $topRight) / $moduleSize); $tlblCentersDimension = MathUtils::round(ResultPoint::distance($topLeft, $bottomLeft) / $moduleSize); $dimension = ($tltrCentersDimension + $tlblCentersDimension) / 2 + 7; switch ($dimension & 0x3) { // mod 4 case 0: $dimension++; break; // 1? do nothing // 1? do nothing case 2: $dimension--; break; case 3: throw NotFoundException::getNotFoundInstance(); } return $dimension; }
function __construct($posX, $posY, $estimatedModuleSize, $count = 1) { parent::__construct($posX, $posY); $this->estimatedModuleSize = $estimatedModuleSize; $this->count = $count; }