Search in sources :

Example 81 with ResultPoint

use of com.google.zxing.ResultPoint in project collect by opendatakit.

the class BarcodeViewDecoder method waitForBarcode.

public LiveData<BarcodeResult> waitForBarcode(DecoratedBarcodeView view) {
    MutableLiveData<BarcodeResult> liveData = new MutableLiveData<>();
    view.decodeContinuous(new BarcodeCallback() {

        @Override
        public void barcodeResult(BarcodeResult result) {
            liveData.setValue(result);
        }

        @Override
        public void possibleResultPoints(List<ResultPoint> resultPoints) {
        }
    });
    return liveData;
}
Also used : BarcodeResult(com.journeyapps.barcodescanner.BarcodeResult) BarcodeCallback(com.journeyapps.barcodescanner.BarcodeCallback) ResultPoint(com.google.zxing.ResultPoint) MutableLiveData(androidx.lifecycle.MutableLiveData)

Example 82 with ResultPoint

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

the class AztecReader method decode.

@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException, FormatException {
    NotFoundException notFoundException = null;
    FormatException formatException = null;
    Detector detector = new Detector(image.getBlackMatrix());
    ResultPoint[] points = null;
    DecoderResult decoderResult = null;
    try {
        AztecDetectorResult detectorResult = detector.detect(false);
        points = detectorResult.getPoints();
        decoderResult = new Decoder().decode(detectorResult);
    } catch (NotFoundException e) {
        notFoundException = e;
    } catch (FormatException e) {
        formatException = e;
    }
    if (decoderResult == null) {
        try {
            AztecDetectorResult detectorResult = detector.detect(true);
            points = detectorResult.getPoints();
            decoderResult = new Decoder().decode(detectorResult);
        } catch (NotFoundException | FormatException e) {
            if (notFoundException != null) {
                throw notFoundException;
            }
            if (formatException != null) {
                throw formatException;
            }
            throw e;
        }
    }
    if (hints != null) {
        ResultPointCallback rpcb = (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
        if (rpcb != null) {
            for (ResultPoint point : points) {
                rpcb.foundPossibleResultPoint(point);
            }
        }
    }
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), decoderResult.getNumBits(), points, BarcodeFormat.AZTEC, System.currentTimeMillis());
    List<byte[]> byteSegments = decoderResult.getByteSegments();
    if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
    }
    String ecLevel = decoderResult.getECLevel();
    if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
    }
    return result;
}
Also used : ResultPointCallback(com.google.zxing.ResultPointCallback) ResultPoint(com.google.zxing.ResultPoint) NotFoundException(com.google.zxing.NotFoundException) Decoder(com.google.zxing.aztec.decoder.Decoder) FormatException(com.google.zxing.FormatException) Result(com.google.zxing.Result) DecoderResult(com.google.zxing.common.DecoderResult) Detector(com.google.zxing.aztec.detector.Detector) DecoderResult(com.google.zxing.common.DecoderResult)

Example 83 with ResultPoint

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

the class Detector method detect.

/**
 * Detects an Aztec Code in an image.
 *
 * @param isMirror if true, image is a mirror-image of original
 * @return {@link AztecDetectorResult} encapsulating results of detecting an Aztec Code
 * @throws NotFoundException if no Aztec Code can be found
 */
public AztecDetectorResult detect(boolean isMirror) throws NotFoundException {
    // 1. Get the center of the aztec matrix
    Point pCenter = getMatrixCenter();
    // 2. Get the center points of the four diagonal points just outside the bull's eye
    // [topRight, bottomRight, bottomLeft, topLeft]
    ResultPoint[] bullsEyeCorners = getBullsEyeCorners(pCenter);
    if (isMirror) {
        ResultPoint temp = bullsEyeCorners[0];
        bullsEyeCorners[0] = bullsEyeCorners[2];
        bullsEyeCorners[2] = temp;
    }
    // 3. Get the size of the matrix and other parameters from the bull's eye
    extractParameters(bullsEyeCorners);
    // 4. Sample the grid
    BitMatrix bits = sampleGrid(image, bullsEyeCorners[shift % 4], bullsEyeCorners[(shift + 1) % 4], bullsEyeCorners[(shift + 2) % 4], bullsEyeCorners[(shift + 3) % 4]);
    // 5. Get the corners of the matrix.
    ResultPoint[] corners = getMatrixCornerPoints(bullsEyeCorners);
    return new AztecDetectorResult(bits, corners, compact, nbDataBlocks, nbLayers);
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint) BitMatrix(com.google.zxing.common.BitMatrix) AztecDetectorResult(com.google.zxing.aztec.AztecDetectorResult)

Example 84 with ResultPoint

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

the class Detector method extractParameters.

/**
 * Extracts the number of data layers and data blocks from the layer around the bull's eye.
 *
 * @param bullsEyeCorners the array of bull's eye corners
 * @throws NotFoundException in case of too many errors or invalid parameters
 */
private void extractParameters(ResultPoint[] bullsEyeCorners) throws NotFoundException {
    if (!isValid(bullsEyeCorners[0]) || !isValid(bullsEyeCorners[1]) || !isValid(bullsEyeCorners[2]) || !isValid(bullsEyeCorners[3])) {
        throw NotFoundException.getNotFoundInstance();
    }
    int length = 2 * nbCenterLayers;
    // Get the bits around the bull's eye
    int[] sides = { // Right side
    sampleLine(bullsEyeCorners[0], bullsEyeCorners[1], length), // Bottom
    sampleLine(bullsEyeCorners[1], bullsEyeCorners[2], length), // Left side
    sampleLine(bullsEyeCorners[2], bullsEyeCorners[3], length), // Top
    sampleLine(bullsEyeCorners[3], bullsEyeCorners[0], length) };
    // bullsEyeCorners[shift] is the corner of the bulls'eye that has three
    // orientation marks.
    // sides[shift] is the row/column that goes from the corner with three
    // orientation marks to the corner with two.
    shift = getRotation(sides, length);
    // Flatten the parameter bits into a single 28- or 40-bit long
    long parameterData = 0;
    for (int i = 0; i < 4; i++) {
        int side = sides[(shift + i) % 4];
        if (compact) {
            // Each side of the form ..XXXXXXX. where Xs are parameter data
            parameterData <<= 7;
            parameterData += (side >> 1) & 0x7F;
        } else {
            // Each side of the form ..XXXXX.XXXXX. where Xs are parameter data
            parameterData <<= 10;
            parameterData += ((side >> 2) & (0x1f << 5)) + ((side >> 1) & 0x1F);
        }
    }
    // Corrects parameter data using RS.  Returns just the data portion
    // without the error correction.
    int correctedData = getCorrectedParameterData(parameterData, compact);
    if (compact) {
        // 8 bits:  2 bits layers and 6 bits data blocks
        nbLayers = (correctedData >> 6) + 1;
        nbDataBlocks = (correctedData & 0x3F) + 1;
    } else {
        // 16 bits:  5 bits layers and 11 bits data blocks
        nbLayers = (correctedData >> 11) + 1;
        nbDataBlocks = (correctedData & 0x7FF) + 1;
    }
}
Also used : ResultPoint(com.google.zxing.ResultPoint)

Example 85 with ResultPoint

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

the class ViewfinderView method onDraw.

@SuppressLint("DrawAllocation")
@Override
public void onDraw(Canvas canvas) {
    if (cameraManager == null) {
        // not ready yet, early draw before done configuring
        return;
    }
    Rect frame = cameraManager.getFramingRect();
    Rect previewFrame = cameraManager.getFramingRectInPreview();
    if (frame == null || previewFrame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();
    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);
    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        paint.setAlpha(CURRENT_POINT_OPACITY);
        canvas.drawBitmap(resultBitmap, null, frame, paint);
    } else {
        // Draw a red "laser scanner" line through the middle to show decoding is active
        paint.setColor(laserColor);
        paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
        scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
        int middle = frame.height() / 2 + frame.top;
        canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
        float scaleX = frame.width() / (float) previewFrame.width();
        float scaleY = frame.height() / (float) previewFrame.height();
        List<ResultPoint> currentPossible = possibleResultPoints;
        List<ResultPoint> currentLast = lastPossibleResultPoints;
        int frameLeft = frame.left;
        int frameTop = frame.top;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new ArrayList<>(5);
            lastPossibleResultPoints = currentPossible;
            paint.setAlpha(CURRENT_POINT_OPACITY);
            paint.setColor(resultPointColor);
            synchronized (currentPossible) {
                for (ResultPoint point : currentPossible) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint);
                }
            }
        }
        if (currentLast != null) {
            paint.setAlpha(CURRENT_POINT_OPACITY / 2);
            paint.setColor(resultPointColor);
            synchronized (currentLast) {
                float radius = POINT_SIZE / 2.0f;
                for (ResultPoint point : currentLast) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint);
                }
            }
        }
        // Request another update at the animation interval, but only repaint the laser line,
        // not the entire viewfinder mask.
        postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE);
    }
}
Also used : Rect(android.graphics.Rect) ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

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