com.google.zxing.pdf417.PDF417Common Java Examples

The following examples show how to use com.google.zxing.pdf417.PDF417Common. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PDF417CodewordDecoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
Example #2
Source File: PDF417CodewordDecoder.java    From weex with Apache License 2.0 6 votes vote down vote up
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
Example #3
Source File: PDF417CodewordDecoder.java    From weex with Apache License 2.0 6 votes vote down vote up
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
Example #4
Source File: PDF417ScanningDecoder.java    From weex with Apache License 2.0 6 votes vote down vote up
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
Example #5
Source File: PDF417ScanningDecoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
Example #6
Source File: PDF417CodewordDecoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
Example #7
Source File: PDF417CodewordDecoder.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = MathUtils.sum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
Example #8
Source File: PDF417CodewordDecoder.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = MathUtils.sum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
Example #9
Source File: PDF417ScanningDecoder.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
Example #10
Source File: PDF417ScanningDecoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
Example #11
Source File: PDF417CodewordDecoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
Example #12
Source File: PDF417CodewordDecoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
Example #13
Source File: DetectionResult.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
Example #14
Source File: DetectionResult.java    From weex with Apache License 2.0 5 votes vote down vote up
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
Example #15
Source File: PDF417ScanningDecoder.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
Example #16
Source File: BarcodeValue.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
Example #17
Source File: PDF417ScanningDecoder.java    From weex with Apache License 2.0 5 votes vote down vote up
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
Example #18
Source File: BarcodeValue.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
Example #19
Source File: DetectionResult.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
Example #20
Source File: BarcodeValue.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
Example #21
Source File: PDF417ScanningDecoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
Example #22
Source File: PDF417ScanningDecoder.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
Example #23
Source File: DetectionResult.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
Example #24
Source File: BarcodeValue.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
Example #25
Source File: PDF417CodewordDecoder.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
private static int getDecodedCodewordValue(int[] moduleBitCount) {
  int decodedValue = getBitValue(moduleBitCount);
  return PDF417Common.getCodeword(decodedValue) == -1 ? -1 : decodedValue;
}
 
Example #26
Source File: DetectionResultRowIndicatorColumn.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
BarcodeMetadata getBarcodeMetadata() {
  Codeword[] codewords = getCodewords();
  BarcodeValue barcodeColumnCount = new BarcodeValue();
  BarcodeValue barcodeRowCountUpperPart = new BarcodeValue();
  BarcodeValue barcodeRowCountLowerPart = new BarcodeValue();
  BarcodeValue barcodeECLevel = new BarcodeValue();
  for (Codeword codeword : codewords) {
    if (codeword == null) {
      continue;
    }
    codeword.setRowNumberAsRowIndicatorColumn();
    int rowIndicatorValue = codeword.getValue() % 30;
    int codewordRowNumber = codeword.getRowNumber();
    if (!isLeft) {
      codewordRowNumber += 2;
    }
    switch (codewordRowNumber % 3) {
      case 0:
        barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1);
        break;
      case 1:
        barcodeECLevel.setValue(rowIndicatorValue / 3);
        barcodeRowCountLowerPart.setValue(rowIndicatorValue % 3);
        break;
      case 2:
        barcodeColumnCount.setValue(rowIndicatorValue + 1);
        break;
    }
  }
  // Maybe we should check if we have ambiguous values?
  if ((barcodeColumnCount.getValue().length == 0) ||
      (barcodeRowCountUpperPart.getValue().length == 0) ||
      (barcodeRowCountLowerPart.getValue().length == 0) ||
      (barcodeECLevel.getValue().length == 0) ||
      barcodeColumnCount.getValue()[0] < 1 ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] < PDF417Common.MIN_ROWS_IN_BARCODE ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] > PDF417Common.MAX_ROWS_IN_BARCODE) {
    return null;
  }
  BarcodeMetadata barcodeMetadata = new BarcodeMetadata(barcodeColumnCount.getValue()[0],
      barcodeRowCountUpperPart.getValue()[0], barcodeRowCountLowerPart.getValue()[0], barcodeECLevel.getValue()[0]);
  removeIncorrectCodewords(codewords, barcodeMetadata);
  return barcodeMetadata;
}
 
Example #27
Source File: PDF417ScanningDecoder.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private static Codeword detectCodeword(BitMatrix image,
                                       int minColumn,
                                       int maxColumn,
                                       boolean leftToRight,
                                       int startColumn,
                                       int imageRow,
                                       int minCodewordWidth,
                                       int maxCodewordWidth) {
  startColumn = adjustCodewordStartColumn(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  // we usually know fairly exact now how long a codeword is. We should provide minimum and maximum expected length
  // and try to adjust the read pixels, e.g. remove single pixel errors or try to cut off exceeding pixels.
  // min and maxCodewordWidth should not be used as they are calculated for the whole barcode an can be inaccurate
  // for the current position
  int[] moduleBitCount = getModuleBitCount(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  if (moduleBitCount == null) {
    return null;
  }
  int endColumn;
  int codewordBitCount = MathUtils.sum(moduleBitCount);
  if (leftToRight) {
    endColumn = startColumn + codewordBitCount;
  } else {
    for (int i = 0; i < moduleBitCount.length / 2; i++) {
      int tmpCount = moduleBitCount[i];
      moduleBitCount[i] = moduleBitCount[moduleBitCount.length - 1 - i];
      moduleBitCount[moduleBitCount.length - 1 - i] = tmpCount;
    }
    endColumn = startColumn;
    startColumn = endColumn - codewordBitCount;
  }
  // TODO implement check for width and correction of black and white bars
  // use start (and maybe stop pattern) to determine if black bars are wider than white bars. If so, adjust.
  // should probably done only for codewords with a lot more than 17 bits. 
  // The following fixes 10-1.png, which has wide black bars and small white bars
  //    for (int i = 0; i < moduleBitCount.length; i++) {
  //      if (i % 2 == 0) {
  //        moduleBitCount[i]--;
  //      } else {
  //        moduleBitCount[i]++;
  //      }
  //    }

  // We could also use the width of surrounding codewords for more accurate results, but this seems
  // sufficient for now
  if (!checkCodewordSkew(codewordBitCount, minCodewordWidth, maxCodewordWidth)) {
    // We could try to use the startX and endX position of the codeword in the same column in the previous row,
    // create the bit count from it and normalize it to 8. This would help with single pixel errors.
    return null;
  }

  int decodedValue = PDF417CodewordDecoder.getDecodedValue(moduleBitCount);
  int codeword = PDF417Common.getCodeword(decodedValue);
  if (codeword == -1) {
    return null;
  }
  return new Codeword(startColumn, endColumn, getCodewordBucketNumber(decodedValue), codeword);
}
 
Example #28
Source File: PDF417ScanningDecoder.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
private static Codeword detectCodeword(BitMatrix image,
                                       int minColumn,
                                       int maxColumn,
                                       boolean leftToRight,
                                       int startColumn,
                                       int imageRow,
                                       int minCodewordWidth,
                                       int maxCodewordWidth) {
  startColumn = adjustCodewordStartColumn(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  // we usually know fairly exact now how long a codeword is. We should provide minimum and maximum expected length
  // and try to adjust the read pixels, e.g. remove single pixel errors or try to cut off exceeding pixels.
  // min and maxCodewordWidth should not be used as they are calculated for the whole barcode an can be inaccurate
  // for the current position
  int[] moduleBitCount = getModuleBitCount(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  if (moduleBitCount == null) {
    return null;
  }
  int endColumn;
  int codewordBitCount = PDF417Common.getBitCountSum(moduleBitCount);
  if (leftToRight) {
    endColumn = startColumn + codewordBitCount;
  } else {
    for (int i = 0; i < moduleBitCount.length / 2; i++) {
      int tmpCount = moduleBitCount[i];
      moduleBitCount[i] = moduleBitCount[moduleBitCount.length - 1 - i];
      moduleBitCount[moduleBitCount.length - 1 - i] = tmpCount;
    }
    endColumn = startColumn;
    startColumn = endColumn - codewordBitCount;
  }
  // TODO implement check for width and correction of black and white bars
  // use start (and maybe stop pattern) to determine if blackbars are wider than white bars. If so, adjust.
  // should probably done only for codewords with a lot more than 17 bits. 
  // The following fixes 10-1.png, which has wide black bars and small white bars
  //    for (int i = 0; i < moduleBitCount.length; i++) {
  //      if (i % 2 == 0) {
  //        moduleBitCount[i]--;
  //      } else {
  //        moduleBitCount[i]++;
  //      }
  //    }

  // We could also use the width of surrounding codewords for more accurate results, but this seems
  // sufficient for now
  if (!checkCodewordSkew(codewordBitCount, minCodewordWidth, maxCodewordWidth)) {
    // We could try to use the startX and endX position of the codeword in the same column in the previous row,
    // create the bit count from it and normalize it to 8. This would help with single pixel errors.
    return null;
  }

  int decodedValue = PDF417CodewordDecoder.getDecodedValue(moduleBitCount);
  int codeword = PDF417Common.getCodeword(decodedValue);
  if (codeword == -1) {
    return null;
  }
  return new Codeword(startColumn, endColumn, getCodewordBucketNumber(decodedValue), codeword);
}
 
Example #29
Source File: DetectionResultRowIndicatorColumn.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
BarcodeMetadata getBarcodeMetadata() {
  Codeword[] codewords = getCodewords();
  BarcodeValue barcodeColumnCount = new BarcodeValue();
  BarcodeValue barcodeRowCountUpperPart = new BarcodeValue();
  BarcodeValue barcodeRowCountLowerPart = new BarcodeValue();
  BarcodeValue barcodeECLevel = new BarcodeValue();
  for (Codeword codeword : codewords) {
    if (codeword == null) {
      continue;
    }
    codeword.setRowNumberAsRowIndicatorColumn();
    int rowIndicatorValue = codeword.getValue() % 30;
    int codewordRowNumber = codeword.getRowNumber();
    if (!isLeft) {
      codewordRowNumber += 2;
    }
    switch (codewordRowNumber % 3) {
      case 0:
        barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1);
        break;
      case 1:
        barcodeECLevel.setValue(rowIndicatorValue / 3);
        barcodeRowCountLowerPart.setValue(rowIndicatorValue % 3);
        break;
      case 2:
        barcodeColumnCount.setValue(rowIndicatorValue + 1);
        break;
    }
  }
  // Maybe we should check if we have ambiguous values?
  if ((barcodeColumnCount.getValue().length == 0) ||
      (barcodeRowCountUpperPart.getValue().length == 0) ||
      (barcodeRowCountLowerPart.getValue().length == 0) ||
      (barcodeECLevel.getValue().length == 0) ||
      barcodeColumnCount.getValue()[0] < 1 ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] < PDF417Common.MIN_ROWS_IN_BARCODE ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] > PDF417Common.MAX_ROWS_IN_BARCODE) {
    return null;
  }
  BarcodeMetadata barcodeMetadata = new BarcodeMetadata(barcodeColumnCount.getValue()[0],
      barcodeRowCountUpperPart.getValue()[0], barcodeRowCountLowerPart.getValue()[0], barcodeECLevel.getValue()[0]);
  removeIncorrectCodewords(codewords, barcodeMetadata);
  return barcodeMetadata;
}
 
Example #30
Source File: PDF417CodewordDecoder.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private static int getDecodedCodewordValue(int[] moduleBitCount) {
  int decodedValue = getBitValue(moduleBitCount);
  return PDF417Common.getCodeword(decodedValue) == -1 ? -1 : decodedValue;
}