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()]); } }
public String decodeWithZxing(byte[] data, int width, int height, Rect crop) { MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(changeZXingDecodeDataMode()); Result rawResult = null; PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, crop.left, crop.top, crop.width(), crop.height(), false); if (source != null) { BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(bitmap); } catch (ReaderException re) { // continue } finally { multiFormatReader.reset(); } } return rawResult != null ? rawResult.getText() : null; }
public String decodeWithZxing(Bitmap bitmap) { MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(changeZXingDecodeDataMode()); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); Result rawResult = null; RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); if (source != null) { BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(binaryBitmap); } catch (ReaderException re) { // continue } finally { multiFormatReader.reset(); } } return rawResult != null ? rawResult.getText() : null; }
public Result decodeWithZxing(Bitmap bitmap) { MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(changeZXingDecodeDataMode()); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); Result rawResult = null; RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(binaryBitmap); } catch (ReaderException re) { // continue } finally { multiFormatReader.reset(); } return rawResult; }
@Override protected Result doInBackground(Void... params) { BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource)); Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(3); hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, listener); MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(hints); long start = System.currentTimeMillis(); Result rawResult = null; try { rawResult = multiFormatReader.decodeWithState(bitmap); mBitmap = luminanceSource.renderCroppedGreyScaleBitmap(); long end = System.currentTimeMillis(); Log.d("DecodeThread", "Decode use " + (end - start) + "ms"); } catch (ReaderException re) { } finally { multiFormatReader.reset(); } return rawResult; }
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<DetectorResult>(); 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()]); } }
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()]); } }
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<DetectorResult>(); 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()]); } }
private String decode(byte[] data, int width, int height) { ScannerManager manager = mManager.get(); if (manager == null) { return null; } Rect rect = manager.getFramingRectInPreview(); PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.right, rect.bottom, false); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); try { Result result = reader.decode(bitmap, mHints); return result.getText(); } catch (ReaderException e) { // Ignore as we will repeatedly decode the preview frame return null; } }
public void testFlowWithSetKeyData() { for (int i = 0; i < groupKeyList.size(); i++) { Bitmap bmp = qrReaderWriter.createQrCode(cipher, groupKeyList.get(i), Instant.now(), 200, 200); try { Result decoded = QRReaderWriterTests.decodePureBitmap(bmp); String temporary = decoded.getText(); GroupQRReaderWriter.ScannedGroupKey key = qrReaderWriter.parseCode(temporary, cipher); SecretKey result = cipher.byteArrayToSecretKey(key.getKey().getEncoded()); assertEquals("Key #" + i + " was not recognized : ", groupKeyList.get(i), result); } catch (ReaderException e) { Log.d("KeyToImageAndBackTests", "Key #" + i + " was ignored due to a Reader Error"); keyIgnoredCounter[i]++; } } }
public IAnswerData processImage(Image image) throws ImageProcessingException { MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource( image); Reader reader = new QRCodeReader(); Hashtable hints = new Hashtable(); // hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); try { Result result = reader.decode(source, hints); if ((result != null) && (result.getText() != null)) { String scannedCode = result.getText(); return new StringData(scannedCode); } else { throw new ImageProcessingException("Barcode scanning failed"); } } catch (ReaderException re) { throw new ImageProcessingException("Barcode scanning failed"); } }
private static void assertCorrectImage2binary(String fileName, String expected) throws IOException, NotFoundException { Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName); BufferedImage image = ImageIO.read(path.toFile()); BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image))); int rowNumber = binaryMap.getHeight() / 2; BitArray row = binaryMap.getBlackRow(rowNumber, null); List<ExpandedPair> pairs; try { RSSExpandedReader rssExpandedReader = new RSSExpandedReader(); pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row); } catch (ReaderException re) { fail(re.toString()); return; } BitArray binary = BitArrayBuilder.buildBitArray(pairs); assertEquals(expected, binary.toString()); }
private static void assertCorrectImage2string(String fileName, String expected) throws IOException, NotFoundException { Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName); BufferedImage image = ImageIO.read(path.toFile()); BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image))); int rowNumber = binaryMap.getHeight() / 2; BitArray row = binaryMap.getBlackRow(rowNumber, null); Result result; try { RSSExpandedReader rssExpandedReader = new RSSExpandedReader(); result = rssExpandedReader.decodeRow(rowNumber, row, null); } catch (ReaderException re) { fail(re.toString()); return; } assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat()); assertEquals(expected, result.getText()); }
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedResult expected) throws IOException, NotFoundException { Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName); BufferedImage image = ImageIO.read(path.toFile()); BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image))); int rowNumber = binaryMap.getHeight() / 2; BitArray row = binaryMap.getBlackRow(rowNumber, null); Result theResult; try { RSSExpandedReader rssExpandedReader = new RSSExpandedReader(); theResult = rssExpandedReader.decodeRow(rowNumber, row, null); } catch (ReaderException re) { fail(re.toString()); return; } assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat()); ParsedResult result = ResultParser.parseResult(theResult); assertEquals(expected, result); }