Package com.google.zxing.aztec.detector
Class Detector
java.lang.Object
com.google.zxing.aztec.detector.Detector
Encapsulates logic that can detect an Aztec Code in an image, even if the Aztec Code
is rotated or skewed, or partially obscured.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private static final int[]
private final BitMatrix
private int
private int
private int
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondetect()
detect
(boolean isMirror) Detects an Aztec Code in an image.private static float
private static float
distance
(ResultPoint a, ResultPoint b) private static ResultPoint[]
expandSquare
(ResultPoint[] cornerPoints, int oldSide, int newSide) Expand the square represented by the corner points by pushing out equally in all directionsprivate int
extractParameters
(ResultPoint[] bullsEyeCorners) Extracts the number of data layers and data blocks from the layer around the bull's eye.private ResultPoint[]
getBullsEyeCorners
(Detector.Point pCenter) Finds the corners of a bull-eye centered on the passed point.private int
getColor
(Detector.Point p1, Detector.Point p2) Gets the color of a segmentprivate static Detector.CorrectedParameter
getCorrectedParameterData
(long parameterData, boolean compact) Corrects the parameter bits using Reed-Solomon algorithm.private int
private Detector.Point
getFirstDifferent
(Detector.Point init, boolean color, int dx, int dy) Gets the coordinate of the first point with a different color in the given directionprivate Detector.Point
Finds a candidate center point of an Aztec code from an imageprivate ResultPoint[]
getMatrixCornerPoints
(ResultPoint[] bullsEyeCorners) Gets the Aztec code corners from the bull's eye corners and the parameters.private static int
getRotation
(int[] sides, int length) private boolean
isValid
(int x, int y) private boolean
isValid
(ResultPoint point) private boolean
isWhiteOrBlackRectangle
(Detector.Point p1, Detector.Point p2, Detector.Point p3, Detector.Point p4) private BitMatrix
sampleGrid
(BitMatrix image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomRight, ResultPoint bottomLeft) Creates a BitMatrix by sampling the provided image.private int
sampleLine
(ResultPoint p1, ResultPoint p2, int size) Samples a line.
-
Field Details
-
EXPECTED_CORNER_BITS
private static final int[] EXPECTED_CORNER_BITS -
image
-
compact
private boolean compact -
nbLayers
private int nbLayers -
nbDataBlocks
private int nbDataBlocks -
nbCenterLayers
private int nbCenterLayers -
shift
private int shift
-
-
Constructor Details
-
Detector
-
-
Method Details
-
detect
- Throws:
NotFoundException
-
detect
Detects an Aztec Code in an image.- Parameters:
isMirror
- if true, image is a mirror-image of original- Returns:
AztecDetectorResult
encapsulating results of detecting an Aztec Code- Throws:
NotFoundException
- if no Aztec Code can be found
-
extractParameters
Extracts the number of data layers and data blocks from the layer around the bull's eye.- Parameters:
bullsEyeCorners
- the array of bull's eye corners- Returns:
- the number of errors corrected during parameter extraction
- Throws:
NotFoundException
- in case of too many errors or invalid parameters
-
getRotation
- Throws:
NotFoundException
-
getCorrectedParameterData
private static Detector.CorrectedParameter getCorrectedParameterData(long parameterData, boolean compact) throws NotFoundException Corrects the parameter bits using Reed-Solomon algorithm.- Parameters:
parameterData
- parameter bitscompact
- true if this is a compact Aztec code- Returns:
- the corrected parameter
- Throws:
NotFoundException
- if the array contains too many errors
-
getBullsEyeCorners
Finds the corners of a bull-eye centered on the passed point. This returns the centers of the diagonal points just outside the bull's eye Returns [topRight, bottomRight, bottomLeft, topLeft]- Parameters:
pCenter
- Center point- Returns:
- The corners of the bull-eye
- Throws:
NotFoundException
- If no valid bull-eye can be found
-
getMatrixCenter
Finds a candidate center point of an Aztec code from an image- Returns:
- the center point
-
getMatrixCornerPoints
Gets the Aztec code corners from the bull's eye corners and the parameters.- Parameters:
bullsEyeCorners
- the array of bull's eye corners- Returns:
- the array of aztec code corners
-
sampleGrid
private BitMatrix sampleGrid(BitMatrix image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomRight, ResultPoint bottomLeft) throws NotFoundException Creates a BitMatrix by sampling the provided image. topLeft, topRight, bottomRight, and bottomLeft are the centers of the squares on the diagonal just outside the bull's eye.- Throws:
NotFoundException
-
sampleLine
Samples a line.- Parameters:
p1
- start point (inclusive)p2
- end point (exclusive)size
- number of bits- Returns:
- the array of bits as an int (first bit is high-order bit of result)
-
isWhiteOrBlackRectangle
private boolean isWhiteOrBlackRectangle(Detector.Point p1, Detector.Point p2, Detector.Point p3, Detector.Point p4) - Returns:
- true if the border of the rectangle passed in parameter is compound of white points only or black points only
-
getColor
Gets the color of a segment- Returns:
- 1 if segment more than 90% black, -1 if segment is more than 90% white, 0 else
-
getFirstDifferent
Gets the coordinate of the first point with a different color in the given direction -
expandSquare
Expand the square represented by the corner points by pushing out equally in all directions- Parameters:
cornerPoints
- the corners of the square, which has the bull's eye at its centeroldSide
- the original length of the side of the square in the target bit matrixnewSide
- the new length of the size of the square in the target bit matrix- Returns:
- the corners of the expanded square
-
isValid
private boolean isValid(int x, int y) -
isValid
-
distance
-
distance
-
getDimension
private int getDimension()
-