Search in sources :

Example 11 with MultiFormatReader

use of com.google.zxing.MultiFormatReader in project zxing-android-embedded by journeyapps.

the class DefaultDecoderFactory method createDecoder.

@Override
public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
    Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
    hints.putAll(baseHints);
    if (this.hints != null) {
        hints.putAll(this.hints);
    }
    if (this.decodeFormats != null) {
        hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
    }
    if (characterSet != null) {
        hints.put(DecodeHintType.CHARACTER_SET, characterSet);
    }
    MultiFormatReader reader = new MultiFormatReader();
    reader.setHints(hints);
    return inverted ? new InvertedDecoder(reader) : new Decoder(reader);
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) EnumMap(java.util.EnumMap)

Example 12 with MultiFormatReader

use of com.google.zxing.MultiFormatReader in project camel by apache.

the class BarcodeDataFormat method readImage.

/**
     * Reads the message from a code.
     */
private String readImage(final Exchange exchange, final InputStream stream) throws Exception {
    final MultiFormatReader reader = new MultiFormatReader();
    final BufferedInputStream in = exchange.getContext().getTypeConverter().mandatoryConvertTo(BufferedInputStream.class, stream);
    final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(in))));
    final Result result = reader.decode(bitmap, readerHintMap);
    // write the found barcode format into the header
    exchange.getOut().setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat());
    return result.getText();
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) BufferedInputStream(java.io.BufferedInputStream) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) Result(com.google.zxing.Result)

Example 13 with MultiFormatReader

use of com.google.zxing.MultiFormatReader in project camel by apache.

the class BarcodeTestBase method checkFormat.

private void checkFormat(File file, BarcodeFormat format) throws IOException {
    Reader reader = new MultiFormatReader();
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(file))));
    Result result;
    try {
        result = reader.decode(bitmap);
    } catch (ReaderException ex) {
        throw new IOException(ex);
    }
    assertEquals(format, result.getBarcodeFormat());
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) ImageReader(javax.imageio.ImageReader) MultiFormatReader(com.google.zxing.MultiFormatReader) Reader(com.google.zxing.Reader) IOException(java.io.IOException) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 14 with MultiFormatReader

use of com.google.zxing.MultiFormatReader in project zxing by zxing.

the class DecodeWorker method decode.

private Result[] decode(URI uri, Map<DecodeHintType, ?> hints) throws IOException {
    BufferedImage image = ImageReader.readImage(uri);
    LuminanceSource source;
    if (config.crop == null) {
        source = new BufferedImageLuminanceSource(image);
    } else {
        List<Integer> crop = config.crop;
        source = new BufferedImageLuminanceSource(image, crop.get(0), crop.get(1), crop.get(2), crop.get(3));
    }
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    if (config.dumpBlackPoint) {
        dumpBlackPoint(uri, image, bitmap);
    }
    MultiFormatReader multiFormatReader = new MultiFormatReader();
    Result[] results;
    try {
        if (config.multi) {
            MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(multiFormatReader);
            results = reader.decodeMultiple(bitmap, hints);
        } else {
            results = new Result[] { multiFormatReader.decode(bitmap, hints) };
        }
    } catch (NotFoundException ignored) {
        System.out.println(uri + ": No barcode found");
        return null;
    }
    if (config.brief) {
        System.out.println(uri + ": Success");
    } else {
        StringWriter output = new StringWriter();
        for (Result result : results) {
            ParsedResult parsedResult = ResultParser.parseResult(result);
            output.write(uri + " (format: " + result.getBarcodeFormat() + ", type: " + parsedResult.getType() + "):\n" + "Raw result:\n" + result.getText() + "\n" + "Parsed result:\n" + parsedResult.getDisplayResult() + "\n");
            output.write("Found " + result.getResultPoints().length + " result points.\n");
            for (int pointIndex = 0; pointIndex < result.getResultPoints().length; pointIndex++) {
                ResultPoint rp = result.getResultPoints()[pointIndex];
                output.write("  Point " + pointIndex + ": (" + rp.getX() + ',' + rp.getY() + ')');
                if (pointIndex != result.getResultPoints().length - 1) {
                    output.write('\n');
                }
            }
            output.write('\n');
        }
        System.out.println(output);
    }
    return results;
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) GenericMultipleBarcodeReader(com.google.zxing.multi.GenericMultipleBarcodeReader) ResultPoint(com.google.zxing.ResultPoint) GenericMultipleBarcodeReader(com.google.zxing.multi.GenericMultipleBarcodeReader) MultipleBarcodeReader(com.google.zxing.multi.MultipleBarcodeReader) NotFoundException(com.google.zxing.NotFoundException) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result) ParsedResult(com.google.zxing.client.result.ParsedResult) StringWriter(java.io.StringWriter) LuminanceSource(com.google.zxing.LuminanceSource) ParsedResult(com.google.zxing.client.result.ParsedResult) BinaryBitmap(com.google.zxing.BinaryBitmap)

Example 15 with MultiFormatReader

use of com.google.zxing.MultiFormatReader in project zxing by zxing.

the class GUIRunner method getDecodeText.

private static String getDecodeText(Path file) {
    BufferedImage image;
    try {
        image = ImageReader.readImage(file.toUri());
    } catch (IOException ioe) {
        return ioe.toString();
    }
    LuminanceSource source = new BufferedImageLuminanceSource(image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    try {
        result = new MultiFormatReader().decode(bitmap);
    } catch (ReaderException re) {
        return re.toString();
    }
    return String.valueOf(result.getText());
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) LuminanceSource(com.google.zxing.LuminanceSource) IOException(java.io.IOException) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Aggregations

MultiFormatReader (com.google.zxing.MultiFormatReader)16 BinaryBitmap (com.google.zxing.BinaryBitmap)10 Result (com.google.zxing.Result)10 HybridBinarizer (com.google.zxing.common.HybridBinarizer)10 ReaderException (com.google.zxing.ReaderException)5 DecodeHintType (com.google.zxing.DecodeHintType)4 LuminanceSource (com.google.zxing.LuminanceSource)4 BufferedImageLuminanceSource (com.google.zxing.client.j2se.BufferedImageLuminanceSource)3 BufferedImage (java.awt.image.BufferedImage)3 BarcodeFormat (com.google.zxing.BarcodeFormat)2 RGBLuminanceSource (com.google.zxing.RGBLuminanceSource)2 Reader (com.google.zxing.Reader)2 ResultPoint (com.google.zxing.ResultPoint)2 GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)2 GenericMultipleBarcodeReader (com.google.zxing.multi.GenericMultipleBarcodeReader)2 MultipleBarcodeReader (com.google.zxing.multi.MultipleBarcodeReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 Bitmap (android.graphics.Bitmap)1