Class Detector

java.lang.Object
com.google.zxing.aztec.detector.Detector

public final class Detector extends 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 Details

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

    • Detector

      public Detector(BitMatrix image)
  • Method Details

    • 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:
      AztecDetectorResult encapsulating 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 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
    • 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 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)
    • distance

      private static float distance(Detector.Point a, Detector.Point b)
    • distance

      private static float distance(ResultPoint a, ResultPoint b)
    • getDimension

      private int getDimension()