Package com.google.zxing.aztec.detector
Class Detector
- java.lang.Object
-
- com.google.zxing.aztec.detector.Detector
-
public final class Detector extends java.lang.ObjectEncapsulates 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 Classes Modifier and Type Class Description (package private) static classDetector.CorrectedParameter(package private) static classDetector.Point
-
Field Summary
Fields Modifier and Type Field Description private booleancompactprivate static int[]EXPECTED_CORNER_BITSprivate BitMatriximageprivate intnbCenterLayersprivate intnbDataBlocksprivate intnbLayersprivate intshift
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AztecDetectorResultdetect()AztecDetectorResultdetect(boolean isMirror)Detects an Aztec Code in an image.private static floatdistance(Detector.Point a, Detector.Point b)private static floatdistance(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 intextractParameters(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 intgetColor(Detector.Point p1, Detector.Point p2)Gets the color of a segmentprivate static Detector.CorrectedParametergetCorrectedParameterData(long parameterData, boolean compact)Corrects the parameter bits using Reed-Solomon algorithm.private intgetDimension()private Detector.PointgetFirstDifferent(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.PointgetMatrixCenter()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 intgetRotation(int[] sides, int length)private booleanisValid(int x, int y)private booleanisValid(ResultPoint point)private booleanisWhiteOrBlackRectangle(Detector.Point p1, Detector.Point p2, Detector.Point p3, Detector.Point p4)private BitMatrixsampleGrid(BitMatrix image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomRight, ResultPoint bottomLeft)Creates a BitMatrix by sampling the provided image.private intsampleLine(ResultPoint p1, ResultPoint p2, int size)Samples a line.
-
-
-
Field Detail
-
EXPECTED_CORNER_BITS
private static final int[] EXPECTED_CORNER_BITS
-
image
private final BitMatrix image
-
compact
private boolean compact
-
nbLayers
private int nbLayers
-
nbDataBlocks
private int nbDataBlocks
-
nbCenterLayers
private int nbCenterLayers
-
shift
private int shift
-
-
Constructor Detail
-
Detector
public Detector(BitMatrix image)
-
-
Method Detail
-
detect
public AztecDetectorResult detect() throws NotFoundException
- Throws:
NotFoundException
-
detect
public AztecDetectorResult detect(boolean isMirror) throws NotFoundException
Detects an Aztec Code in an image.- Parameters:
isMirror- if true, image is a mirror-image of original- Returns:
AztecDetectorResultencapsulating results of detecting an Aztec Code- Throws:
NotFoundException- if no Aztec Code can be found
-
extractParameters
private int extractParameters(ResultPoint[] bullsEyeCorners) throws NotFoundException
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
private static int getRotation(int[] sides, int length) throws NotFoundException- 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
private ResultPoint[] getBullsEyeCorners(Detector.Point pCenter) throws NotFoundException
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
private Detector.Point getMatrixCenter()
Finds a candidate center point of an Aztec code from an image- Returns:
- the center point
-
getMatrixCornerPoints
private ResultPoint[] getMatrixCornerPoints(ResultPoint[] bullsEyeCorners)
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
private int sampleLine(ResultPoint p1, ResultPoint p2, int size)
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
private int getColor(Detector.Point p1, Detector.Point p2)
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
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 direction
-
expandSquare
private static ResultPoint[] expandSquare(ResultPoint[] cornerPoints, int oldSide, int newSide)
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
private boolean isValid(ResultPoint point)
-
distance
private static float distance(Detector.Point a, Detector.Point b)
-
distance
private static float distance(ResultPoint a, ResultPoint b)
-
getDimension
private int getDimension()
-
-