Detector
in package
Encapsulates logic that can detect a QR Code in an image, even if the QR Code is rotated or skewed, or partially obscured.
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- Detector constructor.
- detect() : BitMatrix
- Detects a QR Code in an image.
- calculateModuleSize() : float
- Computes an average estimated module size based on estimated derived from the positions of the three finder patterns.
- calculateModuleSizeOneWay() : float
- Estimates module size based on two finder patterns -- it uses #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int) to figure the width of each, measuring along the axis between their centers.
- computeDimension() : int
- 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.
- createTransform() : PerspectiveTransform
- findAlignmentInRegion() : AlignmentPattern|null
- Attempts to locate an alignment pattern in a limited region of the image, which is guessed to contain it.
- sizeOfBlackWhiteBlackRun() : float
- This method traces a line from a po$in the image, in the direction towards another point.
- sizeOfBlackWhiteBlackRunBothWays() : float
- See #sizeOfBlackWhiteBlackRun(int, int, int, int); computes the total width of a finder pattern by looking for a black-white-black run from the center in the direction of another po$(another finder pattern center), and in the opposite direction too.
Properties
$matrix
private
BitMatrix
$matrix
Methods
__construct()
Detector constructor.
public
__construct(LuminanceSourceInterface $source) : mixed
Parameters
- $source : LuminanceSourceInterface
detect()
Detects a QR Code in an image.
public
detect() : BitMatrix
Return values
BitMatrixcalculateModuleSize()
Computes an average estimated module size based on estimated derived from the positions of the three finder patterns.
private
calculateModuleSize(FinderPattern $topLeft, FinderPattern $topRight, FinderPattern $bottomLeft) : float
Parameters
- $topLeft : FinderPattern
- $topRight : FinderPattern
- $bottomLeft : FinderPattern
Tags
Return values
floatcalculateModuleSizeOneWay()
Estimates module size based on two finder patterns -- it uses #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int) to figure the width of each, measuring along the axis between their centers.
private
calculateModuleSizeOneWay(FinderPattern $a, FinderPattern $b) : float
Parameters
- $a : FinderPattern
- $b : FinderPattern
Return values
floatcomputeDimension()
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.
private
computeDimension(FinderPattern $nw, FinderPattern $ne, FinderPattern $sw, float $size) : int
Parameters
- $nw : FinderPattern
- $ne : FinderPattern
- $sw : FinderPattern
- $size : float
Tags
Return values
intcreateTransform()
private
createTransform(FinderPattern $nw, FinderPattern $ne, FinderPattern $sw, int $size[, AlignmentPattern|null $ap = null ]) : PerspectiveTransform
Parameters
- $nw : FinderPattern
- $ne : FinderPattern
- $sw : FinderPattern
- $size : int
- $ap : AlignmentPattern|null = null
Return values
PerspectiveTransformfindAlignmentInRegion()
Attempts to locate an alignment pattern in a limited region of the image, which is guessed to contain it.
private
findAlignmentInRegion(float $overallEstModuleSize, int $estAlignmentX, int $estAlignmentY, float $allowanceFactor) : AlignmentPattern|null
Parameters
- $overallEstModuleSize : float
-
estimated module size so far
- $estAlignmentX : int
-
x coordinate of center of area probably containing alignment pattern
- $estAlignmentY : int
-
y coordinate of above
- $allowanceFactor : float
-
number of pixels in all directions to search from the center
Return values
AlignmentPattern|null —if found, or null otherwise
sizeOfBlackWhiteBlackRun()
This method traces a line from a po$in the image, in the direction towards another point.
private
sizeOfBlackWhiteBlackRun(int $fromX, int $fromY, int $toX, int $toY) : float
It begins in a black region, and keeps going until it finds white, then black, then white again. It reports the distance from the start to this point.
This is used when figuring out how wide a finder pattern is, when the finder pattern may be skewed or rotated.
Parameters
- $fromX : int
- $fromY : int
- $toX : int
- $toY : int
Return values
floatsizeOfBlackWhiteBlackRunBothWays()
See #sizeOfBlackWhiteBlackRun(int, int, int, int); computes the total width of a finder pattern by looking for a black-white-black run from the center in the direction of another po$(another finder pattern center), and in the opposite direction too.
private
sizeOfBlackWhiteBlackRunBothWays(float $fromX, float $fromY, float $toX, float $toY) : float
Parameters
- $fromX : float
- $fromY : float
- $toX : float
- $toY : float