Class 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.

    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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
    • 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 search
        startX - left column from which to start searching
        startY - top row from which to start searching
        width - width of region to search
        height - height of region to search
        moduleSize - estimated module size so far
    • Method Detail

      • 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 detected
        centerJ - center of the section that appears to cross an alignment pattern
        maxCount - 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 scan
        i - row where alignment pattern may be found
        j - end of possible alignment pattern in row
        Returns:
        AlignmentPattern if we have found the same pattern twice, or null if not