Documentation

AlignmentPatternFinder
in package

FinalYes

This class attempts to find alignment patterns in a QR Code. Alignment patterns look like finder patterns but are smaller and appear at regular intervals throughout the image.

At the moment this only looks for the bottom-right alignment pattern.

This is mostly a simplified copy of FinderPatternFinder. It is copied, pasted and stripped down here for maximum performance but does unfortunately duplicate some code.

This class is thread-safe but not reentrant. Each thread must allocate its own object.

Tags
author

Sean Owen

Table of Contents

Properties

$matrix  : BitMatrix
$moduleSize  : float
$possibleCenters  : array<string|int, AlignmentPattern>

Methods

__construct()  : mixed
Creates a finder that will look in a portion of the whole image.
find()  : AlignmentPattern|null
This method attempts to find the bottom-right alignment pattern in the image. It is a bit messy since it's pretty performance-critical and so is written to be fast foremost.
centerFromEnd()  : float
Given a count of black/white/black pixels just seen and an end position, figures the location of the center of this black/white/black run.
crossCheckVertical()  : float|null
After a horizontal scan finds a potential alignment pattern, this method "cross-checks" by scanning down vertically through the center of the possible alignment pattern to see if the same proportion is detected.
foundPatternCross()  : bool
handlePossibleCenter()  : AlignmentPattern|null
This is called when a horizontal scan finds a possible alignment pattern. It will cross-check with a vertical scan, and if successful, will see if this pattern had been found on a previous horizontal scan. If so, we consider it confirmed and conclude we have found the alignment pattern.

Properties

Methods

__construct()

Creates a finder that will look in a portion of the whole image.

public __construct(BitMatrix $matrix, float $moduleSize) : mixed
Parameters
$matrix : BitMatrix

image to search

$moduleSize : float

estimated module size so far

find()

This method attempts to find the bottom-right alignment pattern in the image. It is a bit messy since it's pretty performance-critical and so is written to be fast foremost.

public find(int $startX, int $startY, int $width, int $height) : AlignmentPattern|null
Parameters
$startX : int

left column from which to start searching

$startY : int

top row from which to start searching

$width : int

width of region to search

$height : int

height of region to search

Return values
AlignmentPattern|null

centerFromEnd()

Given a count of black/white/black pixels just seen and an end position, figures the location of the center of this black/white/black run.

private centerFromEnd(array<string|int, int> $stateCount, int $end) : float
Parameters
$stateCount : array<string|int, int>
$end : int
Return values
float

crossCheckVertical()

After a horizontal scan finds a potential alignment pattern, this method "cross-checks" by scanning down vertically through the center of the possible alignment pattern to see if the same proportion is detected.

private crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal) : float|null

$startI row where an alignment pattern was detected $centerJ center of the section that appears to cross an alignment pattern $maxCount maximum reasonable number of modules that should be observed in any reading state, based on the results of the horizontal scan

returns vertical center of alignment pattern, or null if not found

Parameters
$startI : int
$centerJ : int
$maxCount : int
$originalStateCountTotal : int
Return values
float|null

foundPatternCross()

private foundPatternCross(array<string|int, int> $stateCount) : bool
Parameters
$stateCount : array<string|int, int>

count of black/white/black pixels just read

Return values
bool

true if the proportions of the counts is close enough to the 1/1/1 ratios used by alignment patterns to be considered a match

handlePossibleCenter()

This is called when a horizontal scan finds a possible alignment pattern. It will cross-check with a vertical scan, and if successful, will see if this pattern had been found on a previous horizontal scan. If so, we consider it confirmed and conclude we have found the alignment pattern.

private handlePossibleCenter(array<string|int, int> $stateCount, int $i, int $j) : AlignmentPattern|null
Parameters
$stateCount : array<string|int, int>

reading state module counts from horizontal scan

$i : int

row where alignment pattern may be found

$j : int

end of possible alignment pattern in row

Return values
AlignmentPattern|null

if we have found the same pattern twice, or null if not


        
On this page

Search results