Search in sources :

Example 1 with FinderPatternNotFoundException

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

the class FinderPattern method getCenter.

static Point[] getCenter(Line[] crossLines) throws FinderPatternNotFoundException {
    Vector centers = new Vector();
    for (int i = 0; i < crossLines.length - 1; i++) {
        Line compareLine = crossLines[i];
        for (int j = i + 1; j < crossLines.length; j++) {
            Line comparedLine = crossLines[j];
            if (Line.isCross(compareLine, comparedLine)) {
                int x = 0;
                int y = 0;
                if (compareLine.isHorizontal()) {
                    x = compareLine.getCenter().getX();
                    y = comparedLine.getCenter().getY();
                } else {
                    x = comparedLine.getCenter().getX();
                    y = compareLine.getCenter().getY();
                }
                centers.addElement(new Point(x, y));
            }
        }
    }
    Point[] foundPoints = new Point[centers.size()];
    for (int i = 0; i < foundPoints.length; i++) {
        foundPoints[i] = (Point) centers.elementAt(i);
    //System.out.println(foundPoints[i]);
    }
    if (foundPoints.length == 3) {
        canvas.drawPolygon(foundPoints, Color.RED);
        return foundPoints;
    } else
        throw new FinderPatternNotFoundException("Invalid number of Finder Pattern detected");
}
Also used : FinderPatternNotFoundException(jp.sourceforge.qrcode.exception.FinderPatternNotFoundException)

Example 2 with FinderPatternNotFoundException

use of jp.sourceforge.qrcode.exception.FinderPatternNotFoundException 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)

Aggregations

FinderPatternNotFoundException (jp.sourceforge.qrcode.exception.FinderPatternNotFoundException)2 AlignmentPatternNotFoundException (jp.sourceforge.qrcode.exception.AlignmentPatternNotFoundException)1 InvalidVersionException (jp.sourceforge.qrcode.exception.InvalidVersionException)1 SymbolNotFoundException (jp.sourceforge.qrcode.exception.SymbolNotFoundException)1 VersionInformationException (jp.sourceforge.qrcode.exception.VersionInformationException)1