/** * <p>Detects a QR Code in an image.</p> * * @return {@link DetectorResult} encapsulating results of detecting a QR Code * @throws NotFoundException if QR Code cannot be found * @throws FormatException if a QR Code cannot be decoded */ public DetectorResult detect() throws NotFoundException, FormatException { return detect(null); }
/** * <p>Computes an average estimated module size based on estimated derived from the positions * of the three finder patterns.</p> */ protected float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) { // Take the average return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f; }
FinderPattern bottomLeft = info.getBottomLeft(); float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft); if (moduleSize < 1.0f) { throw NotFoundException.getNotFoundInstance(); int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize); Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension); int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7; alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension); BitMatrix bits = sampleGrid(image, transform, dimension);
DecoderResult result = null; try { detectorResult = new Detector(newBitMatrix).detect(decodeHints); result = decoder.decode(detectorResult.getBits(), decodeHints); } catch (ChecksumException | FormatException | NotFoundException e) { detectorResult = new Detector(bitMatrix).detect(decodeHints); result = decoder.decode(detectorResult.getBits(), decodeHints); if (!result.getText().equals(message)) { detectorResult = new Detector(bitMatrix).detect(decodeHints); DecoderResult result = decoder.decode(detectorResult.getBits(), decodeHints); if (!result.getText().equals(message)) {
/** * <p>Detects a QR Code in an image, simply.</p> * * @param hints optional hints to detector * @return {@link NotFoundException} encapsulating results of detecting a QR Code * @throws NotFoundException if QR Code cannot be found * @throws FormatException if a QR Code cannot be decoded */ public DetectorResult detect(Hashtable hints) throws NotFoundException, FormatException { resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback); FinderPatternInfo info = finder.find(hints); return processFinderPatternInfo(info); }
float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
FinderPattern bottomLeft = info.getBottomLeft(); float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft); if (moduleSize < 1.0f) { throw NotFoundException.getNotFoundInstance(); int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize); Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension); int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7; alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension); BitMatrix bits = sampleGrid(image, transform, dimension);
public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, ChecksumException, FormatException { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.getBlackMatrix()); decoderResult = decoder.decode(bits, hints); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints); decoderResult = decoder.decode(detectorResult.getBits(), hints); points = detectorResult.getPoints(); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); if (decoderResult.getByteSegments() != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments()); } if (decoderResult.getECLevel() != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString()); } return result; }
/** * <p>Detects a QR Code in an image.</p> * * @param hints optional hints to detector * @return {@link DetectorResult} encapsulating results of detecting a QR Code * @throws NotFoundException if QR Code cannot be found * @throws FormatException if a QR Code cannot be decoded */ public final DetectorResult detect(Map<DecodeHintType,?> hints) throws NotFoundException, FormatException { resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback); FinderPatternInfo info = finder.find(hints); return processFinderPatternInfo(info); }
/** * See {@link #sizeOfBlackWhiteBlackRun(int, int, int, int)}; computes the total width of * a finder pattern by looking for a black-white-black run from the center in the direction * of another point (another finder pattern center), and in the opposite direction too.</p> */ private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) { float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); // Now count other way -- don't run off image though of course float scale = 1.0f; int otherToX = fromX - (toX - fromX); if (otherToX < 0) { scale = (float) fromX / (float) (fromX - otherToX); otherToX = 0; } else if (otherToX >= image.getWidth()) { scale = (float) (image.getWidth() - 1 - fromX) / (float) (otherToX - fromX); otherToX = image.getWidth() - 1; } int otherToY = (int) (fromY - (toY - fromY) * scale); scale = 1.0f; if (otherToY < 0) { scale = (float) fromY / (float) (fromY - otherToY); otherToY = 0; } else if (otherToY >= image.getHeight()) { scale = (float) (image.getHeight() - 1 - fromY) / (float) (otherToY - fromY); otherToY = image.getHeight() - 1; } otherToX = (int) (fromX + (otherToX - fromX) * scale); result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); return result - 1.0f; // -1 because we counted the middle pixel twice }
FinderPattern bottomLeft = info.getBottomLeft(); float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft); if (moduleSize < 1.0f) { throw NotFoundException.getNotFoundInstance(); int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize); Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension); int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7; alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension); BitMatrix bits = sampleGrid(image, transform, dimension);
/** * <p>Detects a QR Code in an image.</p> * * @return {@link DetectorResult} encapsulating results of detecting a QR Code * @throws NotFoundException if QR Code cannot be found * @throws FormatException if a QR Code cannot be decoded */ public DetectorResult detect() throws NotFoundException, FormatException { return detect(null); }
/** * <p>Computes an average estimated module size based on estimated derived from the positions * of the three finder patterns.</p> * * @param topLeft detected top-left finder pattern center * @param topRight detected top-right finder pattern center * @param bottomLeft detected bottom-left finder pattern center * @return estimated module size */ protected final float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) { // Take the average return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f; }
/** * <p>Detects a QR Code in an image.</p> * * @param hints optional hints to detector * @return {@link DetectorResult} encapsulating results of detecting a QR Code * @throws NotFoundException if QR Code cannot be found * @throws FormatException if a QR Code cannot be decoded */ public final DetectorResult detect(Map<DecodeHintType,?> hints) throws NotFoundException, FormatException { resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback); FinderPatternInfo info = finder.find(hints); return processFinderPatternInfo(info); }
float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
/** * <p>Detects a QR Code in an image, simply.</p> * * @return {@link DetectorResult} encapsulating results of detecting a QR Code * @throws NotFoundException if no QR Code can be found */ public DetectorResult detect() throws NotFoundException, FormatException { return detect(null); }
/** * <p>Computes an average estimated module size based on estimated derived from the positions * of the three finder patterns.</p> * * @param topLeft detected top-left finder pattern center * @param topRight detected top-right finder pattern center * @param bottomLeft detected bottom-left finder pattern center * @return estimated module size */ protected final float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) { // Take the average return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f; }