Class Detector

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

public final class Detector extends Object

Encapsulates logic that can detect a PDF417 Code in an image, even if the PDF417 Code is rotated or skewed, or partially obscured.

  • Field Details

    • INDEXES_START_PATTERN

      private static final int[] INDEXES_START_PATTERN
    • INDEXES_STOP_PATTERN

      private static final int[] INDEXES_STOP_PATTERN
    • MAX_AVG_VARIANCE

      private static final float MAX_AVG_VARIANCE
      See Also:
    • MAX_INDIVIDUAL_VARIANCE

      private static final float MAX_INDIVIDUAL_VARIANCE
      See Also:
    • MAX_STOP_PATTERN_HEIGHT_VARIANCE

      private static final float MAX_STOP_PATTERN_HEIGHT_VARIANCE
      See Also:
    • START_PATTERN

      private static final int[] START_PATTERN
    • STOP_PATTERN

      private static final int[] STOP_PATTERN
    • MAX_PIXEL_DRIFT

      private static final int MAX_PIXEL_DRIFT
      See Also:
    • MAX_PATTERN_DRIFT

      private static final int MAX_PATTERN_DRIFT
      See Also:
    • SKIPPED_ROW_COUNT_MAX

      private static final int SKIPPED_ROW_COUNT_MAX
      See Also:
    • ROW_STEP

      private static final int ROW_STEP
      See Also:
    • BARCODE_MIN_HEIGHT

      private static final int BARCODE_MIN_HEIGHT
      See Also:
    • ROTATIONS

      private static final int[] ROTATIONS
  • Constructor Details

    • Detector

      private Detector()
  • Method Details

    • detect

      public static PDF417DetectorResult detect(BinaryBitmap image, Map<DecodeHintType,?> hints, boolean multiple) throws NotFoundException

      Detects a PDF417 Code in an image. Checks 0, 90, 180, and 270 degree rotations.

      Parameters:
      image - barcode image to decode
      hints - optional hints to detector
      multiple - if true, then the image is searched for multiple codes. If false, then at most one code will be found and returned
      Returns:
      PDF417DetectorResult encapsulating results of detecting a PDF417 code
      Throws:
      NotFoundException - if no PDF417 Code can be found
    • applyRotation

      private static BitMatrix applyRotation(BitMatrix matrix, int rotation)
      Applies a rotation to the supplied BitMatrix.
      Parameters:
      matrix - bit matrix to apply rotation to
      rotation - the degrees of rotation to apply
      Returns:
      BitMatrix with applied rotation
    • detect

      private static List<ResultPoint[]> detect(boolean multiple, BitMatrix bitMatrix)
      Detects PDF417 codes in an image. Only checks 0 degree rotation
      Parameters:
      multiple - if true, then the image is searched for multiple codes. If false, then at most one code will be found and returned
      bitMatrix - bit matrix to detect barcodes in
      Returns:
      List of ResultPoint arrays containing the coordinates of found barcodes
    • findVertices

      private static ResultPoint[] findVertices(BitMatrix matrix, int startRow, int startColumn)
      Locate the vertices and the codewords area of a black blob using the Start and Stop patterns as locators.
      Parameters:
      matrix - the scanned barcode image.
      Returns:
      an array containing the vertices: vertices[0] x, y top left barcode vertices[1] x, y bottom left barcode vertices[2] x, y top right barcode vertices[3] x, y bottom right barcode vertices[4] x, y top left codeword area vertices[5] x, y bottom left codeword area vertices[6] x, y top right codeword area vertices[7] x, y bottom right codeword area
    • copyToResult

      private static void copyToResult(ResultPoint[] result, ResultPoint[] tmpResult, int[] destinationIndexes)
    • findRowsWithPattern

      private static ResultPoint[] findRowsWithPattern(BitMatrix matrix, int height, int width, int startRow, int startColumn, int minHeight, int[] pattern)
    • findGuardPattern

      private static int[] findGuardPattern(BitMatrix matrix, int column, int row, int width, int[] pattern, int[] counters)
      Parameters:
      matrix - row of black/white values to search
      column - x position to start search
      row - y position to start search
      width - the number of pixels to search on this row
      pattern - pattern of counts of number of black and white pixels that are being searched for as a pattern
      counters - array of counters, as long as pattern, to re-use
      Returns:
      start/end horizontal offset of guard pattern, as an array of two ints.
    • patternMatchVariance

      private static float patternMatchVariance(int[] counters, int[] pattern)
      Determines how closely a set of observed counts of runs of black/white values matches a given target pattern. This is reported as the ratio of the total variance from the expected pattern proportions across all pattern elements, to the length of the pattern.
      Parameters:
      counters - observed counters
      pattern - expected pattern
      Returns:
      ratio of total variance between counters and pattern compared to total pattern size