ChecksumException в zxing.qrcode.decoder.decode () - PullRequest
0 голосов
/ 17 июня 2019

Я работаю над модулем, который пишет и читает QR-коды (используется для автоматического разделения и сортировки большого количества документов, отсканированных в одну стопку).

Поскольку у меня нет доступа к сканеру пользователей, я не могу повторно воспроизвести процесс печати страниц с QR-кодом или сканирования стека.Это означает, что я не могу отладить и посмотреть, что я могу изменить в коде на этапе создания QR-кода

В (копировании / вставке) документе от пользователя у меня есть 1 QR-код, который не удается декодироватьс исключением Checksum.

Вот код (короткая версия только в одном методе для отладки и в этом разделе), который я использую для чтения документа, поиска и декодирования QR-кода:

org.apache.pdfbox.pdmodel.PDDocument;
org.apache.pdfbox.rendering.PDFRenderer;

com.google.zxing.*;
com.google.zxing.client.j2se.BufferedImageLu
com.google.zxing.common.BitMatrix;
com.google.zxing.common.DecoderResult;
com.google.zxing.common.DetectorResult;
com.google.zxing.common.HybridBinarizer;
com.google.zxing.qrcode.decoder.Decoder;
com.google.zxing.qrcode.detector.Detector;

public List<Result> getResultList (File file)
{
    String page = "";
    String exception = "load";
    List<Result> results = new ArrayList<>();

    Map<DecodeHintType, Object> hints = new HashMap<>();
    hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
    hints.put(DecodeHintType.CHARACTER_SET, StandardCharsets.UTF_8);
    hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
    hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);



    try (PDDocument pdf = PDDocument.load(file))
    {
        for (int i = 0 ; i < pdf.getNumberOfPages() ; i++)
        {
            try
            {
                page = String.valueOf(i).concat(" : ");

                exception = "image";
                BufferedImage image = new PDFRenderer(pdf).renderImage(i);

                exception = "source";
                BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);

                exception = "binarizer";
                Binarizer binarizer = new HybridBinarizer(source);

                exception = "matrix";
                BitMatrix matrix = binarizer.getBlackMatrix();

                exception = "detector";
                DetectorResult detector = new Detector(matrix).detect();

                exception = "decoder";
                DecoderResult decoder = new Decoder().decode(detector.getBits());
                /* Same exception with (detector.getBits(), hints) */

                exception = "points";
                ResultPoint[] points = detector.getPoints();

                exception = "result";
                Result result = new Result(decoder.getText(), decoder.getRawBytes(), points, BarcodeFormat.QR_CODE);

                exception = "byteSegments";
                List<byte[]> byteSegments = decoder.getByteSegments();

                exception = "ecLevel";
                String ecLevel = decoder.getECLevel();

                exception = "byteSegments != null";
                if (byteSegments != null)
                {
                    result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
                }

                exception = "ecLevel != null";
                if (ecLevel != null)
                {
                    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
                }

                log.info("add : ".concat(page).concat(decoder.getText()));
                results.add(result);
            }
            catch (IOException | NotFoundException | FormatException | ChecksumException e)
            {
                log.error("Error : ".concat(page).concat(" - ").concat(exception), e);
            }
        }
    }
    catch (IOException e)
    {
        log.error(exception, e);
    }

    return results;
}

Кто-нибудь есть идеи, что я мог бы изменить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...