Class AlignmentPatternFinder
- java.lang.Object
-
- com.google.zxing.qrcode.detector.AlignmentPatternFinder
-
final class AlignmentPatternFinder extends java.lang.Object
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.
-
-
Field Summary
Fields Modifier and Type Field Description private int[]
crossCheckStateCount
private int
height
private BitMatrix
image
private float
moduleSize
private java.util.List<AlignmentPattern>
possibleCenters
private ResultPointCallback
resultPointCallback
private int
startX
private int
startY
private int
width
-
Constructor Summary
Constructors Constructor Description AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
Creates a finder that will look in a portion of the whole image.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static float
centerFromEnd(int[] stateCount, int end)
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 float
crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal)
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.(package private) AlignmentPattern
find()
This method attempts to find the bottom-right alignment pattern in the image.private boolean
foundPatternCross(int[] stateCount)
private AlignmentPattern
handlePossibleCenter(int[] stateCount, int i, int j)
This is called when a horizontal scan finds a possible alignment pattern.
-
-
-
Field Detail
-
image
private final BitMatrix image
-
possibleCenters
private final java.util.List<AlignmentPattern> possibleCenters
-
startX
private final int startX
-
startY
private final int startY
-
width
private final int width
-
height
private final int height
-
moduleSize
private final float moduleSize
-
crossCheckStateCount
private final int[] crossCheckStateCount
-
resultPointCallback
private final ResultPointCallback resultPointCallback
-
-
Constructor Detail
-
AlignmentPatternFinder
AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
Creates a finder that will look in a portion of the whole image.
- Parameters:
image
- image to searchstartX
- left column from which to start searchingstartY
- top row from which to start searchingwidth
- width of region to searchheight
- height of region to searchmoduleSize
- estimated module size so far
-
-
Method Detail
-
find
AlignmentPattern find() throws NotFoundException
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.
- Returns:
AlignmentPattern
if found- Throws:
NotFoundException
- if not found
-
centerFromEnd
private static float centerFromEnd(int[] stateCount, int end)
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.
-
foundPatternCross
private boolean foundPatternCross(int[] stateCount)
- Parameters:
stateCount
- count of black/white/black pixels just read- Returns:
- true iff the proportions of the counts is close enough to the 1/1/1 ratios used by alignment patterns to be considered a match
-
crossCheckVertical
private float crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal)
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.
- Parameters:
startI
- row where an alignment pattern was detectedcenterJ
- center of the section that appears to cross an alignment patternmaxCount
- 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
Float.NaN
if not found
-
handlePossibleCenter
private AlignmentPattern handlePossibleCenter(int[] stateCount, int i, int j)
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.
- Parameters:
stateCount
- reading state module counts from horizontal scani
- row where alignment pattern may be foundj
- end of possible alignment pattern in row- Returns:
AlignmentPattern
if we have found the same pattern twice, or null if not
-
-