Search in sources :

Example 96 with ResultPoint

use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.

the class BoundingBox method calculateMinMaxValues.

private void calculateMinMaxValues() {
    if (topLeft == null) {
        topLeft = new ResultPoint(0, topRight.getY());
        bottomLeft = new ResultPoint(0, bottomRight.getY());
    } else if (topRight == null) {
        topRight = new ResultPoint(image.getWidth() - 1, topLeft.getY());
        bottomRight = new ResultPoint(image.getWidth() - 1, bottomLeft.getY());
    }
    minX = (int) Math.min(topLeft.getX(), bottomLeft.getX());
    maxX = (int) Math.max(topRight.getX(), bottomRight.getX());
    minY = (int) Math.min(topLeft.getY(), topRight.getY());
    maxY = (int) Math.max(bottomLeft.getY(), bottomRight.getY());
}
Also used : ResultPoint(com.google.zxing.ResultPoint)

Example 97 with ResultPoint

use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.

the class BoundingBox method addMissingRows.

BoundingBox addMissingRows(int missingStartRows, int missingEndRows, boolean isLeft) throws NotFoundException {
    ResultPoint newTopLeft = topLeft;
    ResultPoint newBottomLeft = bottomLeft;
    ResultPoint newTopRight = topRight;
    ResultPoint newBottomRight = bottomRight;
    if (missingStartRows > 0) {
        ResultPoint top = isLeft ? topLeft : topRight;
        int newMinY = (int) top.getY() - missingStartRows;
        if (newMinY < 0) {
            newMinY = 0;
        }
        ResultPoint newTop = new ResultPoint(top.getX(), newMinY);
        if (isLeft) {
            newTopLeft = newTop;
        } else {
            newTopRight = newTop;
        }
    }
    if (missingEndRows > 0) {
        ResultPoint bottom = isLeft ? bottomLeft : bottomRight;
        int newMaxY = (int) bottom.getY() + missingEndRows;
        if (newMaxY >= image.getHeight()) {
            newMaxY = image.getHeight() - 1;
        }
        ResultPoint newBottom = new ResultPoint(bottom.getX(), newMaxY);
        if (isLeft) {
            newBottomLeft = newBottom;
        } else {
            newBottomRight = newBottom;
        }
    }
    calculateMinMaxValues();
    return new BoundingBox(image, newTopLeft, newBottomLeft, newTopRight, newBottomRight);
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint)

Example 98 with ResultPoint

use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.

the class Detector method correctTopRightRectangular.

/**
 * Calculates the position of the white top right module using the output of the rectangle detector
 * for a rectangular matrix
 */
private ResultPoint correctTopRightRectangular(ResultPoint bottomLeft, ResultPoint bottomRight, ResultPoint topLeft, ResultPoint topRight, int dimensionTop, int dimensionRight) {
    float corr = distance(bottomLeft, bottomRight) / (float) dimensionTop;
    int norm = distance(topLeft, topRight);
    float cos = (topRight.getX() - topLeft.getX()) / norm;
    float sin = (topRight.getY() - topLeft.getY()) / norm;
    ResultPoint c1 = new ResultPoint(topRight.getX() + corr * cos, topRight.getY() + corr * sin);
    corr = distance(bottomLeft, topLeft) / (float) dimensionRight;
    norm = distance(bottomRight, topRight);
    cos = (topRight.getX() - bottomRight.getX()) / norm;
    sin = (topRight.getY() - bottomRight.getY()) / norm;
    ResultPoint c2 = new ResultPoint(topRight.getX() + corr * cos, topRight.getY() + corr * sin);
    if (!isValid(c1)) {
        if (isValid(c2)) {
            return c2;
        }
        return null;
    }
    if (!isValid(c2)) {
        return c1;
    }
    int l1 = Math.abs(dimensionTop - transitionsBetween(topLeft, c1).getTransitions()) + Math.abs(dimensionRight - transitionsBetween(bottomRight, c1).getTransitions());
    int l2 = Math.abs(dimensionTop - transitionsBetween(topLeft, c2).getTransitions()) + Math.abs(dimensionRight - transitionsBetween(bottomRight, c2).getTransitions());
    if (l1 <= l2) {
        return c1;
    }
    return c2;
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint)

Example 99 with ResultPoint

use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.

the class QRCodeDecoderMetaData method applyMirroredCorrection.

/**
 * Apply the result points' order correction due to mirroring.
 *
 * @param points Array of points to apply mirror correction to.
 */
public void applyMirroredCorrection(ResultPoint[] points) {
    if (!mirrored || points == null || points.length < 3) {
        return;
    }
    ResultPoint bottomLeft = points[0];
    points[0] = points[2];
    points[2] = bottomLeft;
// No need to 'fix' top-left and alignment pattern.
}
Also used : ResultPoint(com.google.zxing.ResultPoint)

Example 100 with ResultPoint

use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.

the class Detector method computeDimension.

/**
 * <p>Computes the dimension (number of modules on a size) of the QR Code based on the position
 * of the finder patterns and estimated module size.</p>
 */
private static int computeDimension(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, float moduleSize) throws NotFoundException {
    int tltrCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, topRight) / moduleSize);
    int tlblCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize);
    int dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7;
    switch(// mod 4
    dimension & 0x03) {
        case 0:
            dimension++;
            break;
        // 1? do nothing
        case 2:
            dimension--;
            break;
        case 3:
            throw NotFoundException.getNotFoundInstance();
    }
    return dimension;
}
Also used : ResultPoint(com.google.zxing.ResultPoint)

Aggregations

ResultPoint (com.google.zxing.ResultPoint)252 Result (com.google.zxing.Result)77 Paint (android.graphics.Paint)45 Rect (android.graphics.Rect)24 BitMatrix (com.google.zxing.common.BitMatrix)22 DecoderResult (com.google.zxing.common.DecoderResult)22 NotFoundException (com.google.zxing.NotFoundException)21 DetectorResult (com.google.zxing.common.DetectorResult)20 ArrayList (java.util.ArrayList)20 ReaderException (com.google.zxing.ReaderException)16 SuppressLint (android.annotation.SuppressLint)13 ResultPointCallback (com.google.zxing.ResultPointCallback)12 Canvas (android.graphics.Canvas)10 ResultMetadataType (com.google.zxing.ResultMetadataType)8 BitArray (com.google.zxing.common.BitArray)8 QRCodeDecoderMetaData (com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData)8 BarcodeFormat (com.google.zxing.BarcodeFormat)5 FormatException (com.google.zxing.FormatException)4 Decoder (com.google.zxing.aztec.decoder.Decoder)4 Detector (com.google.zxing.aztec.detector.Detector)4