com.google.zxing.DecodeHintType Java Examples
The following examples show how to use
com.google.zxing.DecodeHintType.
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: PDF417Reader.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 6 votes |
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) throws NotFoundException, FormatException, ChecksumException { List<Result> results = new ArrayList<>(); PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple); for (ResultPoint[] points : detectorResult.getPoints()) { DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5], points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points)); Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417); result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel()); PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther(); if (pdf417ResultMetadata != null) { result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata); } results.add(result); } return results.toArray(new Result[results.size()]); }
Example #2
Source File: PDF417Reader.java From barcodescanner-lib-aar with MIT License | 6 votes |
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) throws NotFoundException, FormatException, ChecksumException { List<Result> results = new ArrayList<>(); PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple); for (ResultPoint[] points : detectorResult.getPoints()) { DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5], points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points)); Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417); result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel()); PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther(); if (pdf417ResultMetadata != null) { result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata); } results.add(result); } return results.toArray(new Result[results.size()]); }
Example #3
Source File: DataMatrixReader.java From reacteu-app with MIT License | 6 votes |
@Override public Result decode(BinaryBitmap image, Map<DecodeHintType,?> 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); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(); decoderResult = decoder.decode(detectorResult.getBits()); points = detectorResult.getPoints(); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.DATA_MATRIX); 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 #4
Source File: CaptureActivityHandler.java From ZXing-Standalone-library with Apache License 2.0 | 6 votes |
CaptureActivityHandler(CaptureActivity activity, Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType,?> baseHints, String characterSet, CameraManager cameraManager) { this.activity = activity; decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet, new ViewfinderResultPointCallback(activity.getViewfinderView())); decodeThread.start(); state = State.SUCCESS; // Start ourselves capturing previews and decoding. this.cameraManager = cameraManager; cameraManager.startPreview(); restartPreviewAndDecode(); }
Example #5
Source File: PDF417Reader.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public Result decode(BinaryBitmap binarybitmap, Map map) { DecoderResult decoderresult; ResultPoint aresultpoint[]; if (map != null && map.containsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bitmatrix = a(binarybitmap.getBlackMatrix()); decoderresult = b.decode(bitmatrix); aresultpoint = a; } else { DetectorResult detectorresult = (new Detector(binarybitmap)).detect(); decoderresult = b.decode(detectorresult.getBits()); aresultpoint = detectorresult.getPoints(); } return new Result(decoderresult.getText(), decoderresult.getRawBytes(), aresultpoint, BarcodeFormat.PDF_417); }
Example #6
Source File: QRCodeReader.java From android-quick-response-code with Apache License 2.0 | 6 votes |
@Override public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> 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); 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 #7
Source File: MultiDetector.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #8
Source File: MultiDetector.java From weex with Apache License 2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #9
Source File: ZxingUtils.java From tysq-android with GNU General Public License v3.0 | 6 votes |
/** * 解析QR图内容 * * @param imageView * @return */ public static String readImage(ImageView imageView) { String content = null; Map<DecodeHintType, String> hints = new HashMap<>(); hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 获得待解析的图片 Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); RGBLuminanceSource source = new RGBLuminanceSource(bitmap); BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); try { Result result = reader.decode(bitmap1, hints); // 得到解析后的文字 content = result.getText(); } catch (Exception e) { e.printStackTrace(); } return content; }
Example #10
Source File: MultiDetector.java From ScreenCapture with MIT License | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #11
Source File: DecodeUtils.java From myapplication with Apache License 2.0 | 6 votes |
private Map<DecodeHintType, Object> changeZXingDecodeDataMode() { Map<DecodeHintType, Object> hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); Collection<BarcodeFormat> decodeFormats = new ArrayList<BarcodeFormat>(); switch (mDataMode) { case DECODE_DATA_MODE_ALL: decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); break; case DECODE_DATA_MODE_QRCODE: decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); break; case DECODE_DATA_MODE_BARCODE: decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); break; } hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); return hints; }
Example #12
Source File: RSS14Reader.java From ScreenCapture with MIT License | 6 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { Pair leftPair = decodePair(row, false, rowNumber, hints); addOrTally(possibleLeftPairs, leftPair); row.reverse(); Pair rightPair = decodePair(row, true, rowNumber, hints); addOrTally(possibleRightPairs, rightPair); row.reverse(); for (Pair left : possibleLeftPairs) { if (left.getCount() > 1) { for (Pair right : possibleRightPairs) { if (right.getCount() > 1 && checkChecksum(left, right)) { return constructResult(left, right); } } } } throw NotFoundException.getNotFoundInstance(); }
Example #13
Source File: Detector.java From barcodescanner-lib-aar with MIT License | 6 votes |
/** * <p>Detects a PDF417 Code in an image. Only checks 0 and 180 degree rotations.</p> * * @param image barcode image to decode * @param hints optional hints to detector * @param multiple if true, then the image is searched for multiple codes. If false, then at most one code will * be found and returned * @return {@link PDF417DetectorResult} encapsulating results of detecting a PDF417 code * @throws NotFoundException if no PDF417 Code can be found */ public static PDF417DetectorResult detect(BinaryBitmap image, Map<DecodeHintType,?> hints, boolean multiple) throws NotFoundException { // TODO detection improvement, tryHarder could try several different luminance thresholds/blackpoints or even // different binarizers //boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); BitMatrix bitMatrix = image.getBlackMatrix(); List<ResultPoint[]> barcodeCoordinates = detect(multiple, bitMatrix); if (barcodeCoordinates.isEmpty()) { bitMatrix = bitMatrix.clone(); bitMatrix.rotate180(); barcodeCoordinates = detect(multiple, bitMatrix); } return new PDF417DetectorResult(bitMatrix, barcodeCoordinates); }
Example #14
Source File: MultiFormatOneDReader.java From ZXing-Orient with Apache License 2.0 | 5 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { for (OneDReader reader : readers) { try { return reader.decodeRow(rowNumber, row, hints); } catch (ReaderException re) { // continue } } throw NotFoundException.getNotFoundInstance(); }
Example #15
Source File: Decoder.java From ZXing-Orient with Apache License 2.0 | 5 votes |
public DecoderResult decode(BitMatrix bits, Map<DecodeHintType,?> hints) throws FormatException, ChecksumException { BitMatrixParser parser = new BitMatrixParser(bits); byte[] codewords = parser.readCodewords(); correctErrors(codewords, 0, 10, 10, ALL); int mode = codewords[0] & 0x0F; byte[] datawords; switch (mode) { case 2: case 3: case 4: correctErrors(codewords, 20, 84, 40, EVEN); correctErrors(codewords, 20, 84, 40, ODD); datawords = new byte[94]; break; case 5: correctErrors(codewords, 20, 68, 56, EVEN); correctErrors(codewords, 20, 68, 56, ODD); datawords = new byte[78]; break; default: throw FormatException.getFormatInstance(); } System.arraycopy(codewords, 0, datawords, 0, 10); System.arraycopy(codewords, 20, datawords, 10, datawords.length - 10); return DecodedBitStreamParser.decode(datawords, mode); }
Example #16
Source File: Detector.java From weex with Apache License 2.0 | 5 votes |
/** * <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); }
Example #17
Source File: DecodeHandler.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
DecodeHandler(QrCodeActivity activity) { this.mActivity = activity; mMultiFormatReader = new MultiFormatReader(); mHints = new Hashtable<>(); mHints.put(DecodeHintType.CHARACTER_SET, "utf-8"); mHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); Collection<BarcodeFormat> barcodeFormats = new ArrayList<>(); barcodeFormats.add(BarcodeFormat.QR_CODE); barcodeFormats.add(BarcodeFormat.CODE_39); barcodeFormats.add(BarcodeFormat.CODE_93); barcodeFormats.add(BarcodeFormat.CODE_128); mHints.put(DecodeHintType.POSSIBLE_FORMATS, barcodeFormats); }
Example #18
Source File: PDF417Reader.java From ZXing-Orient with Apache License 2.0 | 5 votes |
@Override public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException, FormatException, ChecksumException { Result[] result = decode(image, hints, false); if (result == null || result.length == 0 || result[0] == null) { throw NotFoundException.getNotFoundInstance(); } return result[0]; }
Example #19
Source File: QRCodeMultiReader.java From Tesseract-OCR-Scanner with Apache License 2.0 | 5 votes |
@Override public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException { List<Result> results = new ArrayList<>(); DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (DetectorResult detectorResult : detectorResults) { try { DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints); ResultPoint[] points = detectorResult.getPoints(); // If the code was mirrored: swap the bottom-left and the top-right points. if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); 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); } if (decoderResult.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber()); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity()); } results.add(result); } catch (ReaderException re) { // ignore and continue } } if (results.isEmpty()) { return EMPTY_RESULT_ARRAY; } else { results = processStructuredAppend(results); return results.toArray(new Result[results.size()]); } }
Example #20
Source File: DecodeThread.java From myapplication with Apache License 2.0 | 5 votes |
public DecodeThread(CaptureActivity activity, int decodeMode) { this.activity = activity; handlerInitLatch = new CountDownLatch(1); hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); Collection<BarcodeFormat> decodeFormats = new ArrayList<BarcodeFormat>(); decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC)); decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417)); switch (decodeMode) { case BARCODE_MODE: decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); break; case QRCODE_MODE: decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); break; case ALL_MODE: decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats()); decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats()); break; default: break; } hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); }
Example #21
Source File: Decoder.java From reacteu-app with MIT License | 5 votes |
/** * <p>Convenience method that can decode a QR Code represented as a 2D array of booleans. * "true" is taken to mean a black module.</p> * * @param image booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code * @throws FormatException if the QR Code cannot be decoded * @throws ChecksumException if error correction fails */ public DecoderResult decode(boolean[][] image, Map<DecodeHintType,?> hints) throws ChecksumException, FormatException { int dimension = image.length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { if (image[i][j]) { bits.set(j, i); } } } return decode(bits, hints); }
Example #22
Source File: BarcodeUtils.java From code-scanner with MIT License | 5 votes |
@NonNull private static MultiFormatReader createReader(@Nullable final Map<DecodeHintType, ?> hints) { final MultiFormatReader reader = new MultiFormatReader(); if (hints != null) { reader.setHints(hints); } else { reader.setHints(Collections .singletonMap(DecodeHintType.POSSIBLE_FORMATS, CodeScanner.ALL_FORMATS)); } return reader; }
Example #23
Source File: Detector.java From barcodescanner-lib-aar with MIT License | 5 votes |
/** * <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); }
Example #24
Source File: ScanActivity.java From green_android with GNU General Public License v3.0 | 5 votes |
private void decode(final byte[] data) { final PlanarYUVLuminanceSource source = cameraManager.buildLuminanceSource(data); final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, (ResultPointCallback) dot -> runOnUiThread(() -> scannerView.addDot(dot))); final Result scanResult = reader.decode(bitmap, hints); final int thumbnailWidth = source.getThumbnailWidth(); final int thumbnailHeight = source.getThumbnailHeight(); final float thumbnailScaleFactor = (float) thumbnailWidth / source.getWidth(); final Bitmap thumbnailImage = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ARGB_8888); thumbnailImage.setPixels( source.renderThumbnail(), 0, thumbnailWidth, 0, 0, thumbnailWidth, thumbnailHeight); runOnUiThread(() -> handleResult(scanResult, thumbnailImage, thumbnailScaleFactor)); } catch (final ReaderException x) { // retry cameraHandler.post(fetchAndDecodeRunnable); } finally { reader.reset(); } }
Example #25
Source File: QRCodeReader.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
@Override public final Result decode(BinaryBitmap image, Map<DecodeHintType,?> 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(); } // If the code was mirrored: swap the bottom-left and the top-right points. if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); 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); } if (decoderResult.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber()); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity()); } return result; }
Example #26
Source File: Detector.java From ScreenCapture with MIT License | 5 votes |
/** * <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); }
Example #27
Source File: OneDReader.java From weex with Apache License 2.0 | 5 votes |
@Override public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException, FormatException { try { return doDecode(image, hints); } catch (NotFoundException nfe) { boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.isRotateSupported()) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); Result result = doDecode(rotatedImage, hints); // Record that we found it rotated 90 degrees CCW / 270 degrees CW Map<ResultMetadataType,?> metadata = result.getResultMetadata(); int orientation = 270; if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) { // But if we found it reversed in doDecode(), add in that result here: orientation = (orientation + (Integer) metadata.get(ResultMetadataType.ORIENTATION)) % 360; } result.putMetadata(ResultMetadataType.ORIENTATION, orientation); // Update result points ResultPoint[] points = result.getResultPoints(); if (points != null) { int height = rotatedImage.getHeight(); for (int i = 0; i < points.length; i++) { points[i] = new ResultPoint(height - points[i].getY() - 1, points[i].getX()); } } return result; } else { throw nfe; } } }
Example #28
Source File: RSS14Reader.java From ZXing-Orient with Apache License 2.0 | 5 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { Pair leftPair = decodePair(row, false, rowNumber, hints); addOrTally(possibleLeftPairs, leftPair); row.reverse(); Pair rightPair = decodePair(row, true, rowNumber, hints); addOrTally(possibleRightPairs, rightPair); row.reverse(); int lefSize = possibleLeftPairs.size(); for (int i = 0; i < lefSize; i++) { Pair left = possibleLeftPairs.get(i); if (left.getCount() > 1) { int rightSize = possibleRightPairs.size(); for (int j = 0; j < rightSize; j++) { Pair right = possibleRightPairs.get(j); if (right.getCount() > 1) { if (checkChecksum(left, right)) { return constructResult(left, right); } } } } } throw NotFoundException.getNotFoundInstance(); }
Example #29
Source File: UPCAReader.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Map<DecodeHintType,?> hints) throws NotFoundException, FormatException, ChecksumException { return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints)); }
Example #30
Source File: DecodeThread.java From BarcodeEye with Apache License 2.0 | 5 votes |
DecodeThread(CaptureActivity activity, Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType,?> baseHints, String characterSet, ResultPointCallback resultPointCallback) { this.activity = activity; handlerInitLatch = new CountDownLatch(1); hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class); if (baseHints != null) { hints.putAll(baseHints); } // The prefs can't change while the thread is running, so pick them up once here. if (decodeFormats == null || decodeFormats.isEmpty()) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); decodeFormats = EnumSet.noneOf(BarcodeFormat.class); // TODO: Make configurable? // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D, false)) { // decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_QR, false)) { // decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); // } // if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_DATA_MATRIX, false)) { // decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); // } } hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); if (characterSet != null) { hints.put(DecodeHintType.CHARACTER_SET, characterSet); } hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); Log.i("DecodeThread", "Hints: " + hints); }