Search in sources :

Example 51 with ResultPoint

use of com.google.zxing.ResultPoint in project incubator-weex by apache.

the class MonochromeRectangleDetector method findCornerFromCenter.

/**
 * Attempts to locate a corner of the barcode by scanning up, down, left or right from a center
 * point which should be within the barcode.
 *
 * @param centerX center's x component (horizontal)
 * @param deltaX same as deltaY but change in x per step instead
 * @param left minimum value of x
 * @param right maximum value of x
 * @param centerY center's y component (vertical)
 * @param deltaY change in y per step. If scanning up this is negative; down, positive;
 *  left or right, 0
 * @param top minimum value of y to search through (meaningless when di == 0)
 * @param bottom maximum value of y
 * @param maxWhiteRun maximum run of white pixels that can still be considered to be within
 *  the barcode
 * @return a {@link com.google.zxing.ResultPoint} encapsulating the corner that was found
 * @throws NotFoundException if such a point cannot be found
 */
private ResultPoint findCornerFromCenter(int centerX, int deltaX, int left, int right, int centerY, int deltaY, int top, int bottom, int maxWhiteRun) throws NotFoundException {
    int[] lastRange = null;
    for (int y = centerY, x = centerX; y < bottom && y >= top && x < right && x >= left; y += deltaY, x += deltaX) {
        int[] range;
        if (deltaX == 0) {
            // horizontal slices, up and down
            range = blackWhiteRange(y, maxWhiteRun, left, right, true);
        } else {
            // vertical slices, left and right
            range = blackWhiteRange(x, maxWhiteRun, top, bottom, false);
        }
        if (range == null) {
            if (lastRange == null) {
                throw NotFoundException.getNotFoundInstance();
            }
            // lastRange was found
            if (deltaX == 0) {
                int lastY = y - deltaY;
                if (lastRange[0] < centerX) {
                    if (lastRange[1] > centerX) {
                        // straddle, choose one or the other based on direction
                        return new ResultPoint(deltaY > 0 ? lastRange[0] : lastRange[1], lastY);
                    }
                    return new ResultPoint(lastRange[0], lastY);
                } else {
                    return new ResultPoint(lastRange[1], lastY);
                }
            } else {
                int lastX = x - deltaX;
                if (lastRange[0] < centerY) {
                    if (lastRange[1] > centerY) {
                        return new ResultPoint(lastX, deltaX < 0 ? lastRange[0] : lastRange[1]);
                    }
                    return new ResultPoint(lastX, lastRange[0]);
                } else {
                    return new ResultPoint(lastX, lastRange[1]);
                }
            }
        }
        lastRange = range;
    }
    throw NotFoundException.getNotFoundInstance();
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint)

Example 52 with ResultPoint

use of com.google.zxing.ResultPoint in project incubator-weex by apache.

the class Detector method sampleLine.

/**
 * Samples a line.
 *
 * @param p1   start point (inclusive)
 * @param p2   end point (exclusive)
 * @param size number of bits
 * @return the array of bits as an int (first bit is high-order bit of result)
 */
private int sampleLine(ResultPoint p1, ResultPoint p2, int size) {
    int result = 0;
    float d = distance(p1, p2);
    float moduleSize = d / size;
    float px = p1.getX();
    float py = p1.getY();
    float dx = moduleSize * (p2.getX() - p1.getX()) / d;
    float dy = moduleSize * (p2.getY() - p1.getY()) / d;
    for (int i = 0; i < size; i++) {
        if (image.get(MathUtils.round(px + i * dx), MathUtils.round(py + i * dy))) {
            result |= 1 << (size - i - 1);
        }
    }
    return result;
}
Also used : ResultPoint(com.google.zxing.ResultPoint)

Example 53 with ResultPoint

use of com.google.zxing.ResultPoint in project incubator-weex by apache.

the class Detector method sampleGrid.

/**
 * Creates a BitMatrix by sampling the provided image.
 * topLeft, topRight, bottomRight, and bottomLeft are the centers of the squares on the
 * diagonal just outside the bull's eye.
 */
private BitMatrix sampleGrid(BitMatrix image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomRight, ResultPoint bottomLeft) throws NotFoundException {
    GridSampler sampler = GridSampler.getInstance();
    int dimension = getDimension();
    float low = dimension / 2.0f - nbCenterLayers;
    float high = dimension / 2.0f + nbCenterLayers;
    return sampler.sampleGrid(image, dimension, dimension, // topleft
    low, // topleft
    low, // topright
    high, // topright
    low, // bottomright
    high, // bottomright
    high, // bottomleft
    low, // bottomleft
    high, topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRight.getX(), bottomRight.getY(), bottomLeft.getX(), bottomLeft.getY());
}
Also used : GridSampler(com.google.zxing.common.GridSampler) ResultPoint(com.google.zxing.ResultPoint)

Example 54 with ResultPoint

use of com.google.zxing.ResultPoint in project incubator-weex by apache.

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)

Example 55 with ResultPoint

use of com.google.zxing.ResultPoint in project incubator-weex by apache.

the class FinderPatternFinder method findRowSkip.

/**
 * @return number of rows we could safely skip during scanning, based on the first
 *         two finder patterns that have been located. In some cases their position will
 *         allow us to infer that the third pattern must lie below a certain point farther
 *         down in the image.
 */
private int findRowSkip() {
    int max = possibleCenters.size();
    if (max <= 1) {
        return 0;
    }
    ResultPoint firstConfirmedCenter = null;
    for (FinderPattern center : possibleCenters) {
        if (center.getCount() >= CENTER_QUORUM) {
            if (firstConfirmedCenter == null) {
                firstConfirmedCenter = center;
            } else {
                // We have two confirmed centers
                // How far down can we skip before resuming looking for the next
                // pattern? In the worst case, only the difference between the
                // difference in the x / y coordinates of the two centers.
                // This is the case where you find top left last.
                hasSkipped = true;
                return (int) (Math.abs(firstConfirmedCenter.getX() - center.getX()) - Math.abs(firstConfirmedCenter.getY() - center.getY())) / 2;
            }
        }
    }
    return 0;
}
Also used : ResultPoint(com.google.zxing.ResultPoint) 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