Search in sources :

Example 71 with Result

use of com.google.zxing.Result 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 72 with Result

use of com.google.zxing.Result 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)

Example 73 with Result

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

the class URIParsedResultTestCase method doTest.

private static void doTest(String contents, String uri, String title) {
    Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
    ParsedResult result = ResultParser.parseResult(fakeResult);
    assertSame(ParsedResultType.URI, result.getType());
    URIParsedResult uriResult = (URIParsedResult) result;
    assertEquals(uri, uriResult.getURI());
    assertEquals(title, uriResult.getTitle());
}
Also used : Result(com.google.zxing.Result)

Example 74 with Result

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

the class VINParsedResultTestCase method doTest.

private static void doTest(String contents, String wmi, String vds, String vis, String country, String attributes, int year, char plant, String sequential) {
    Result fakeResult = new Result(contents, null, null, BarcodeFormat.CODE_39);
    ParsedResult result = ResultParser.parseResult(fakeResult);
    assertSame(ParsedResultType.VIN, result.getType());
    VINParsedResult vinResult = (VINParsedResult) result;
    assertEquals(wmi, vinResult.getWorldManufacturerID());
    assertEquals(vds, vinResult.getVehicleDescriptorSection());
    assertEquals(vis, vinResult.getVehicleIdentifierSection());
    assertEquals(country, vinResult.getCountryCode());
    assertEquals(attributes, vinResult.getVehicleAttributes());
    assertEquals(year, vinResult.getModelYear());
    assertEquals(plant, vinResult.getPlantCode());
    assertEquals(sequential, vinResult.getSequentialNumber());
}
Also used : Result(com.google.zxing.Result)

Example 75 with Result

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

the class VINParsedResultTestCase method testNotVIN.

@Test
public void testNotVIN() {
    Result fakeResult = new Result("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39);
    ParsedResult result = ResultParser.parseResult(fakeResult);
    assertEquals(ParsedResultType.TEXT, result.getType());
    fakeResult = new Result("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128);
    result = ResultParser.parseResult(fakeResult);
    assertEquals(ParsedResultType.TEXT, result.getType());
}
Also used : Result(com.google.zxing.Result) Test(org.junit.Test)

Aggregations

Result (com.google.zxing.Result)117 ResultPoint (com.google.zxing.ResultPoint)43 BinaryBitmap (com.google.zxing.BinaryBitmap)37 ReaderException (com.google.zxing.ReaderException)35 HybridBinarizer (com.google.zxing.common.HybridBinarizer)30 Bundle (android.os.Bundle)19 Message (android.os.Message)17 DecoderResult (com.google.zxing.common.DecoderResult)14 ArrayList (java.util.ArrayList)14 MultiFormatReader (com.google.zxing.MultiFormatReader)11 NotFoundException (com.google.zxing.NotFoundException)11 PlanarYUVLuminanceSource (com.google.zxing.PlanarYUVLuminanceSource)11 Cursor (android.database.Cursor)9 LuminanceSource (com.google.zxing.LuminanceSource)9 BitArray (com.google.zxing.common.BitArray)8 DetectorResult (com.google.zxing.common.DetectorResult)8 BufferedImage (java.awt.image.BufferedImage)8 Test (org.junit.Test)8 Bitmap (android.graphics.Bitmap)7 Handler (android.os.Handler)7