Class Detector


  • public final class Detector
    extends java.lang.Object
    Encapsulates logic that can detect an Aztec Code in an image, even if the Aztec Code is rotated or skewed, or partially obscured.
    • Field Detail

      • EXPECTED_CORNER_BITS

        private static final int[] EXPECTED_CORNER_BITS
      • 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

      • 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
      • getCorrectedParameterData

        private static Detector.CorrectedParameter getCorrectedParameterData​(long parameterData,
                                                                             boolean compact)
                                                                      throws NotFoundException
        Corrects the parameter bits using Reed-Solomon algorithm.
        Parameters:
        parameterData - parameter bits
        compact - 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
      • 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)
      • 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 center
        oldSide - the original length of the side of the square in the target bit matrix
        newSide - 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)
      • getDimension

        private int getDimension()