Java Code Examples for com.google.zxing.ResultPointCallback#foundPossibleResultPoint()

The following examples show how to use com.google.zxing.ResultPointCallback#foundPossibleResultPoint() . 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: RSS14Reader.java    From ScreenCapture with MIT License 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 2
Source File: RSS14Reader.java    From Tesseract-OCR-Scanner with Apache License 2.0 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 3
Source File: RSS14Reader.java    From QrCodeScanner with GNU General Public License v3.0 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 4
Source File: RSS14Reader.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 5
Source File: RSS14Reader.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 6
Source File: RSS14Reader.java    From weex with Apache License 2.0 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 7
Source File: RSS14Reader.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example 8
Source File: RSS14Reader.java    From reacteu-app with MIT License 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException re) {
    return null;
  }
}
 
Example 9
Source File: AztecReader.java    From reacteu-app with MIT License 5 votes vote down vote up
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException {

  AztecDetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
  ResultPoint[] points = detectorResult.getPoints();

  if (hints != null) {
    ResultPointCallback rpcb = (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
    if (rpcb != null) {
      for (ResultPoint point : points) {
        rpcb.foundPossibleResultPoint(point);
      }
    }
  }

  DecoderResult decoderResult = new Decoder().decode(detectorResult);

  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.AZTEC);
  
  List<byte[]> byteSegments = decoderResult.getByteSegments();
  if (byteSegments != null) {
    result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
  }
  String ecLevel = decoderResult.getECLevel();
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  
  return result;
}
 
Example 10
Source File: AztecReader.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public Result decode(BinaryBitmap binarybitmap, Map map)
{
    AztecDetectorResult aztecdetectorresult = (new Detector(binarybitmap.getBlackMatrix())).detect();
    com.google.zxing.ResultPoint aresultpoint[] = aztecdetectorresult.getPoints();
    if (map != null)
    {
        ResultPointCallback resultpointcallback = (ResultPointCallback)map.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
        if (resultpointcallback != null)
        {
            int i = aresultpoint.length;
            for (int j = 0; j < i; j++)
            {
                resultpointcallback.foundPossibleResultPoint(aresultpoint[j]);
            }

        }
    }
    DecoderResult decoderresult = (new Decoder()).decode(aztecdetectorresult);
    Result result = new Result(decoderresult.getText(), decoderresult.getRawBytes(), aresultpoint, BarcodeFormat.AZTEC);
    java.util.List list = decoderresult.getByteSegments();
    if (list != null)
    {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, list);
    }
    String s = decoderresult.getECLevel();
    if (s != null)
    {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, s);
    }
    return result;
}
 
Example 11
Source File: UPCEANReader.java    From reacteu-app with MIT License 4 votes vote down vote up
/**
 * <p>Like {@link #decodeRow(int, BitArray, java.util.Map)}, but
 * allows caller to inform method about where the UPC/EAN start pattern is
 * found. This allows this to be computed once and reused across many implementations.</p>
 */
public Result decodeRow(int rowNumber,
                        BitArray row,
                        int[] startGuardRange,
                        Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {

  ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

  if (resultPointCallback != null) {
    resultPointCallback.foundPossibleResultPoint(new ResultPoint(
        (startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber
    ));
  }

  StringBuilder result = decodeRowStringBuffer;
  result.setLength(0);
  int endStart = decodeMiddle(row, startGuardRange, result);

  if (resultPointCallback != null) {
    resultPointCallback.foundPossibleResultPoint(new ResultPoint(
        endStart, rowNumber
    ));
  }

  int[] endRange = decodeEnd(row, endStart);

  if (resultPointCallback != null) {
    resultPointCallback.foundPossibleResultPoint(new ResultPoint(
        (endRange[0] + endRange[1]) / 2.0f, rowNumber
    ));
  }


  // Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
  // spec might want more whitespace, but in practice this is the maximum we can count on.
  int end = endRange[1];
  int quietEnd = end + (end - endRange[0]);
  if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
    throw NotFoundException.getNotFoundInstance();
  }

  String resultString = result.toString();
  if (!checkChecksum(resultString)) {
    throw ChecksumException.getChecksumInstance();
  }

  float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
  float right = (float) (endRange[1] + endRange[0]) / 2.0f;
  BarcodeFormat format = getBarcodeFormat();
  Result decodeResult = new Result(resultString,
      null, // no natural byte representation for these barcodes
      new ResultPoint[]{
          new ResultPoint(left, (float) rowNumber),
          new ResultPoint(right, (float) rowNumber)},
      format);

  try {
    Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
    decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.getText());
    decodeResult.putAllMetadata(extensionResult.getResultMetadata());
    decodeResult.addResultPoints(extensionResult.getResultPoints());
  } catch (ReaderException re) {
    // continue
  }

  if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A) {
    String countryID = eanManSupport.lookupCountryIdentifier(resultString);
    if (countryID != null) {
      decodeResult.putMetadata(ResultMetadataType.POSSIBLE_COUNTRY, countryID);
    }
  }

  return decodeResult;
}