Package com.google.zxing.pdf417.detector
Class Detector
- java.lang.Object
-
- com.google.zxing.pdf417.detector.Detector
-
public final class Detector extends java.lang.ObjectEncapsulates logic that can detect a PDF417 Code in an image, even if the PDF417 Code is rotated or skewed, or partially obscured.
-
-
Field Summary
Fields Modifier and Type Field Description private static intBARCODE_MIN_HEIGHTprivate static int[]INDEXES_START_PATTERNprivate static int[]INDEXES_STOP_PATTERNprivate static floatMAX_AVG_VARIANCEprivate static floatMAX_INDIVIDUAL_VARIANCEprivate static intMAX_PATTERN_DRIFTprivate static intMAX_PIXEL_DRIFTprivate static floatMAX_STOP_PATTERN_HEIGHT_VARIANCEprivate static int[]ROTATIONSprivate static intROW_STEPprivate static intSKIPPED_ROW_COUNT_MAXprivate static int[]START_PATTERNprivate static int[]STOP_PATTERN
-
Constructor Summary
Constructors Modifier Constructor Description privateDetector()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static BitMatrixapplyRotation(BitMatrix matrix, int rotation)Applies a rotation to the supplied BitMatrix.private static voidcopyToResult(ResultPoint[] result, ResultPoint[] tmpResult, int[] destinationIndexes)private static java.util.List<ResultPoint[]>detect(boolean multiple, BitMatrix bitMatrix)Detects PDF417 codes in an image.static PDF417DetectorResultdetect(BinaryBitmap image, java.util.Map<DecodeHintType,?> hints, boolean multiple)Detects a PDF417 Code in an image.private static int[]findGuardPattern(BitMatrix matrix, int column, int row, int width, int[] pattern, int[] counters)private static ResultPoint[]findRowsWithPattern(BitMatrix matrix, int height, int width, int startRow, int startColumn, int minHeight, int[] pattern)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.private static floatpatternMatchVariance(int[] counters, int[] pattern)Determines how closely a set of observed counts of runs of black/white values matches a given target pattern.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
MAX_INDIVIDUAL_VARIANCE
private static final float MAX_INDIVIDUAL_VARIANCE
- See Also:
- Constant Field Values
-
MAX_STOP_PATTERN_HEIGHT_VARIANCE
private static final float MAX_STOP_PATTERN_HEIGHT_VARIANCE
- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
MAX_PATTERN_DRIFT
private static final int MAX_PATTERN_DRIFT
- See Also:
- Constant Field Values
-
SKIPPED_ROW_COUNT_MAX
private static final int SKIPPED_ROW_COUNT_MAX
- See Also:
- Constant Field Values
-
ROW_STEP
private static final int ROW_STEP
- See Also:
- Constant Field Values
-
BARCODE_MIN_HEIGHT
private static final int BARCODE_MIN_HEIGHT
- See Also:
- Constant Field Values
-
ROTATIONS
private static final int[] ROTATIONS
-
-
Method Detail
-
detect
public static PDF417DetectorResult detect(BinaryBitmap image, java.util.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 decodehints- optional hints to detectormultiple- if true, then the image is searched for multiple codes. If false, then at most one code will be found and returned- Returns:
PDF417DetectorResultencapsulating 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 torotation- the degrees of rotation to apply- Returns:
- BitMatrix with applied rotation
-
detect
private static java.util.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 returnedbitMatrix- 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 searchcolumn- x position to start searchrow- y position to start searchwidth- the number of pixels to search on this rowpattern- pattern of counts of number of black and white pixels that are being searched for as a patterncounters- 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 counterspattern- expected pattern- Returns:
- ratio of total variance between counters and pattern compared to total pattern size
-
-