Search in sources :

Example 1 with SymbolNotFoundException

use of jp.sourceforge.qrcode.exception.SymbolNotFoundException in project qrcode by yanbe.

the class QRCodeDecoder method decode.

DecodeResult decode(QRCodeImage qrCodeImage, Point adjust) throws DecodingFailedException {
    try {
        if (numTryDecode == 0) {
            canvas.println("Decoding started");
            int[][] intImage = imageToIntArray(qrCodeImage);
            imageReader = new QRCodeImageReader();
            qrCodeSymbol = imageReader.getQRCodeSymbol(intImage);
        } else {
            canvas.println("--");
            canvas.println("Decoding restarted #" + (numTryDecode));
            qrCodeSymbol = imageReader.getQRCodeSymbolWithAdjustedGrid(adjust);
        }
    } catch (SymbolNotFoundException e) {
        throw new DecodingFailedException(e.getMessage());
    }
    canvas.println("Created QRCode symbol.");
    canvas.println("Reading symbol.");
    canvas.println("Version: " + qrCodeSymbol.getVersionReference());
    canvas.println("Mask pattern: " + qrCodeSymbol.getMaskPatternRefererAsString());
    // blocks contains all (data and RS) blocks in QR Code symbol
    int[] blocks = qrCodeSymbol.getBlocks();
    canvas.println("Correcting data errors.");
    // now blocks turn to data blocks (corrected and extracted from original blocks)
    blocks = correctDataBlocks(blocks);
    try {
        byte[] decodedByteArray = getDecodedByteArray(blocks, qrCodeSymbol.getVersion(), qrCodeSymbol.getNumErrorCollectionCode());
        return new DecodeResult(decodedByteArray, numLastCorrectionFailures);
    } catch (InvalidDataBlockException e) {
        canvas.println(e.getMessage());
        throw new DecodingFailedException(e.getMessage());
    }
}
Also used : QRCodeImageReader(jp.sourceforge.qrcode.reader.QRCodeImageReader) InvalidDataBlockException(jp.sourceforge.qrcode.exception.InvalidDataBlockException) SymbolNotFoundException(jp.sourceforge.qrcode.exception.SymbolNotFoundException) DecodingFailedException(jp.sourceforge.qrcode.exception.DecodingFailedException)

Example 2 with SymbolNotFoundException

use of jp.sourceforge.qrcode.exception.SymbolNotFoundException in project qrcode by yanbe.

the class QRCodeImageReader method getQRCodeSymbol.

public QRCodeSymbol getQRCodeSymbol(int[][] image) throws SymbolNotFoundException {
    int longSide = (image.length < image[0].length) ? image[0].length : image.length;
    QRCodeImageReader.DECIMAL_POINT = 23 - QRCodeUtility.sqrt(longSide / 256);
    bitmap = filterImage(image);
    canvas.println("Drawing matrix.");
    canvas.drawMatrix(bitmap);
    canvas.println("Scanning Finder Pattern.");
    FinderPattern finderPattern = null;
    try {
        finderPattern = FinderPattern.findFinderPattern(bitmap);
    } catch (FinderPatternNotFoundException e) {
        canvas.println("Not found, now retrying...");
        bitmap = applyCrossMaskingMedianFilter(bitmap, 5);
        canvas.drawMatrix(bitmap);
        try {
            finderPattern = FinderPattern.findFinderPattern(bitmap);
        } catch (FinderPatternNotFoundException e2) {
            throw new SymbolNotFoundException(e2.getMessage());
        } catch (VersionInformationException e2) {
            throw new SymbolNotFoundException(e2.getMessage());
        }
    } catch (VersionInformationException e) {
        throw new SymbolNotFoundException(e.getMessage());
    }
    canvas.println("FinderPattern at");
    String finderPatternCoordinates = finderPattern.getCenter(FinderPattern.UL).toString() + finderPattern.getCenter(FinderPattern.UR).toString() + finderPattern.getCenter(FinderPattern.DL).toString();
    canvas.println(finderPatternCoordinates);
    int[] sincos = finderPattern.getAngle();
    canvas.println("Angle*4098: Sin " + Integer.toString(sincos[0]) + "  " + "Cos " + Integer.toString(sincos[1]));
    int version = finderPattern.getVersion();
    canvas.println("Version: " + Integer.toString(version));
    if (version < 1 || version > 40)
        throw new InvalidVersionException("Invalid version: " + version);
    AlignmentPattern alignmentPattern = null;
    try {
        alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern);
    } catch (AlignmentPatternNotFoundException e) {
        throw new SymbolNotFoundException(e.getMessage());
    }
    int matrixLength = alignmentPattern.getCenter().length;
    canvas.println("AlignmentPatterns at");
    for (int y = 0; y < matrixLength; y++) {
        String alignmentPatternCoordinates = "";
        for (int x = 0; x < matrixLength; x++) {
            alignmentPatternCoordinates += alignmentPattern.getCenter()[x][y].toString();
        }
        canvas.println(alignmentPatternCoordinates);
    }
    //for(int i = 0; i < 500000; i++) System.out.println("");
    canvas.println("Creating sampling grid.");
    //[TODO] need all-purpose method
    //samplingGrid = getSamplingGrid2_6(finderPattern, alignmentPattern);
    samplingGrid = getSamplingGrid(finderPattern, alignmentPattern);
    canvas.println("Reading grid.");
    boolean[][] qRCodeMatrix = null;
    try {
        qRCodeMatrix = getQRCodeMatrix(bitmap, samplingGrid);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new SymbolNotFoundException("Sampling grid exceeded image boundary");
    }
    //canvas.drawMatrix(qRCodeMatrix);
    return new QRCodeSymbol(qRCodeMatrix);
}
Also used : VersionInformationException(jp.sourceforge.qrcode.exception.VersionInformationException) InvalidVersionException(jp.sourceforge.qrcode.exception.InvalidVersionException) FinderPatternNotFoundException(jp.sourceforge.qrcode.exception.FinderPatternNotFoundException) AlignmentPatternNotFoundException(jp.sourceforge.qrcode.exception.AlignmentPatternNotFoundException) SymbolNotFoundException(jp.sourceforge.qrcode.exception.SymbolNotFoundException)

Example 3 with SymbolNotFoundException

use of jp.sourceforge.qrcode.exception.SymbolNotFoundException in project qrcode by yanbe.

the class QRCodeImageReader method getQRCodeSymbolWithAdjustedGrid.

public QRCodeSymbol getQRCodeSymbolWithAdjustedGrid(Point adjust) throws IllegalStateException, SymbolNotFoundException {
    if (bitmap == null || samplingGrid == null) {
        throw new IllegalStateException("This method must be called after QRCodeImageReader.getQRCodeSymbol() called");
    }
    samplingGrid.adjust(adjust);
    canvas.println("Sampling grid adjusted d(" + adjust.getX() + "," + adjust.getY() + ")");
    boolean[][] qRCodeMatrix = null;
    try {
        qRCodeMatrix = getQRCodeMatrix(bitmap, samplingGrid);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new SymbolNotFoundException("Sampling grid exceeded image boundary");
    }
    return new QRCodeSymbol(qRCodeMatrix);
}
Also used : SymbolNotFoundException(jp.sourceforge.qrcode.exception.SymbolNotFoundException)

Aggregations

SymbolNotFoundException (jp.sourceforge.qrcode.exception.SymbolNotFoundException)3 AlignmentPatternNotFoundException (jp.sourceforge.qrcode.exception.AlignmentPatternNotFoundException)1 DecodingFailedException (jp.sourceforge.qrcode.exception.DecodingFailedException)1 FinderPatternNotFoundException (jp.sourceforge.qrcode.exception.FinderPatternNotFoundException)1 InvalidDataBlockException (jp.sourceforge.qrcode.exception.InvalidDataBlockException)1 InvalidVersionException (jp.sourceforge.qrcode.exception.InvalidVersionException)1 VersionInformationException (jp.sourceforge.qrcode.exception.VersionInformationException)1 QRCodeImageReader (jp.sourceforge.qrcode.reader.QRCodeImageReader)1