com.google.zxing.ResultPoint Java Examples

The following examples show how to use com.google.zxing.ResultPoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Detector.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Estimates module size based on two finder patterns -- it uses
 * {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
 * width of each, measuring along the axis between their centers.</p>
 */
private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
  float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
      (int) pattern.getY(),
      (int) otherPattern.getX(),
      (int) otherPattern.getY());
  float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int) otherPattern.getX(),
      (int) otherPattern.getY(),
      (int) pattern.getX(),
      (int) pattern.getY());
  if (Float.isNaN(moduleSizeEst1)) {
    return moduleSizeEst2 / 7.0f;
  }
  if (Float.isNaN(moduleSizeEst2)) {
    return moduleSizeEst1 / 7.0f;
  }
  // Average them, and divide by 7 since we've counted the width of 3 black modules,
  // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
  return (moduleSizeEst1 + moduleSizeEst2) / 14.0f;
}
 
Example #2
Source File: Detector.java    From android-quick-response-code with Apache License 2.0 6 votes vote down vote up
public static PerspectiveTransform createTransform(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, ResultPoint alignmentPattern, int dimension) {
    float dimMinusThree = dimension - 3.5f;
    float bottomRightX;
    float bottomRightY;
    float sourceBottomRightX;
    float sourceBottomRightY;
    if (alignmentPattern != null) {
        bottomRightX = alignmentPattern.getX();
        bottomRightY = alignmentPattern.getY();
        sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f;
    } else {
        // Don't have an alignment pattern, just make up the bottom-right
        // point
        bottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX();
        bottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY();
        sourceBottomRightX = sourceBottomRightY = dimMinusThree;
    }

    return PerspectiveTransform.quadrilateralToQuadrilateral(3.5f, 3.5f, dimMinusThree, 3.5f, sourceBottomRightX, sourceBottomRightY, 3.5f, dimMinusThree,
            topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRightX, bottomRightY, bottomLeft.getX(), bottomLeft.getY());
}
 
Example #3
Source File: UPCEANExtension2Support.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
                       new ResultPoint((float) end, (float) rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
 
Example #4
Source File: QRCodeReaderView.java    From flutter_qr_reader with MIT License 6 votes vote down vote up
/**
 * Transform result to surfaceView coordinates
 * <p>
 * This method is needed because coordinates are given in landscape google.zxing.client.android.android.com.google.zxing.client.android.camera coordinates when
 * device is in portrait mode and different coordinates otherwise.
 *
 * @return a new PointF array with transformed points
 */
private PointF[] transformToViewCoordinates(QRCodeReaderView view,
                                            ResultPoint[] resultPoints) {
    int orientationDegrees = view.getCameraDisplayOrientation();
    Orientation orientation =
            orientationDegrees == 90 || orientationDegrees == 270 ? Orientation.PORTRAIT
                    : Orientation.LANDSCAPE;
    Point viewSize = new Point(view.getWidth(), view.getHeight());
    Point cameraPreviewSize = view.mCameraManager.getPreviewSize();
    boolean isMirrorCamera =
            view.mCameraManager.getPreviewCameraId()
                    == Camera.CameraInfo.CAMERA_FACING_FRONT;

    return qrToViewPointTransformer.transform(resultPoints, isMirrorCamera, orientation,
            viewSize, cameraPreviewSize);
}
 
Example #5
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * Expand the square represented by the corner points by pushing out equally in all directions
 *
 * @param cornerPoints the corners of the square, which has the bull's eye at its center
 * @param oldSide the original length of the side of the square in the target bit matrix
 * @param newSide the new length of the size of the square in the target bit matrix
 * @return the corners of the expanded square
 */
private static ResultPoint[] expandSquare(ResultPoint[] cornerPoints, float oldSide, float newSide) {
  float ratio = newSide / (2 * oldSide);
  float dx = cornerPoints[0].getX() - cornerPoints[2].getX();
  float dy = cornerPoints[0].getY() - cornerPoints[2].getY();
  float centerx = (cornerPoints[0].getX() + cornerPoints[2].getX()) / 2.0f;
  float centery = (cornerPoints[0].getY() + cornerPoints[2].getY()) / 2.0f;

  ResultPoint result0 = new ResultPoint(centerx + ratio * dx, centery + ratio * dy);
  ResultPoint result2 = new ResultPoint(centerx - ratio * dx, centery - ratio * dy);

  dx = cornerPoints[1].getX() - cornerPoints[3].getX();
  dy = cornerPoints[1].getY() - cornerPoints[3].getY();
  centerx = (cornerPoints[1].getX() + cornerPoints[3].getX()) / 2.0f;
  centery = (cornerPoints[1].getY() + cornerPoints[3].getY()) / 2.0f;
  ResultPoint result1 = new ResultPoint(centerx + ratio * dx, centery + ratio * dy);
  ResultPoint result3 = new ResultPoint(centerx - ratio * dx, centery - ratio * dy);

  return new ResultPoint[]{result0, result1, result2, result3};
}
 
Example #6
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * <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 (dimension & 0x03) { // mod 4
    case 0:
      dimension++;
      break;
      // 1? do nothing
    case 2:
      dimension--;
      break;
    case 3:
      throw NotFoundException.getNotFoundInstance();
  }
  return dimension;
}
 
Example #7
Source File: UPCEANExtension5Support.java    From reacteu-app with MIT License 6 votes vote down vote up
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
                       new ResultPoint((float) end, (float) rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
 
Example #8
Source File: QRCodeReader.java    From reacteu-app with MIT License 6 votes vote down vote up
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  ResultPoint[] points;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
    decoderResult = decoder.decode(detectorResult.getBits(), hints);
    points = detectorResult.getPoints();
  }

  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
  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;
}
 
Example #9
Source File: FinderPatternFinder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example #10
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * 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,
                            low, low,   // topleft
                            high, low,  // topright
                            high, high, // bottomright
                            low, high,  // bottomleft
                            topLeft.getX(), topLeft.getY(),
                            topRight.getX(), topRight.getY(),
                            bottomRight.getX(), bottomRight.getY(),
                            bottomLeft.getX(), bottomLeft.getY());
}
 
Example #11
Source File: GenericMultipleBarcodeReader.java    From ScreenCapture with MIT License 6 votes vote down vote up
private static Result translateResultPoints(Result result, int xOffset, int yOffset) {
  ResultPoint[] oldResultPoints = result.getResultPoints();
  if (oldResultPoints == null) {
    return result;
  }
  ResultPoint[] newResultPoints = new ResultPoint[oldResultPoints.length];
  for (int i = 0; i < oldResultPoints.length; i++) {
    ResultPoint oldPoint = oldResultPoints[i];
    if (oldPoint != null) {
      newResultPoints[i] = new ResultPoint(oldPoint.getX() + xOffset, oldPoint.getY() + yOffset);
    }
  }
  Result newResult = new Result(result.getText(),
                                result.getRawBytes(),
                                result.getNumBits(),
                                newResultPoints,
                                result.getBarcodeFormat(),
                                result.getTimestamp());
  newResult.putAllMetadata(result.getResultMetadata());
  return newResult;
}
 
Example #12
Source File: RSS14Reader.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
Example #13
Source File: Detector.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * 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,
                            low, low,   // topleft
                            high, low,  // topright
                            high, high, // bottomright
                            low, high,  // bottomleft
                            topLeft.getX(), topLeft.getY(),
                            topRight.getX(), topRight.getY(),
                            bottomRight.getX(), bottomRight.getY(),
                            bottomLeft.getX(), bottomLeft.getY());
}
 
Example #14
Source File: FinderPatternFinder.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
/**
 * @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;
}
 
Example #15
Source File: UPCEANExtension2Support.java    From ScreenCapture with MIT License 6 votes vote down vote up
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
                       new ResultPoint(end, rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
 
Example #16
Source File: UPCEANExtension5Support.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
                       new ResultPoint(end, rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
 
Example #17
Source File: UPCEANExtension5Support.java    From ScreenCapture with MIT License 6 votes vote down vote up
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
                       new ResultPoint(end, rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
 
Example #18
Source File: Detector.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Estimates module size based on two finder patterns -- it uses
 * {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
 * width of each, measuring along the axis between their centers.</p>
 */
private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
  float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
      (int) pattern.getY(),
      (int) otherPattern.getX(),
      (int) otherPattern.getY());
  float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int) otherPattern.getX(),
      (int) otherPattern.getY(),
      (int) pattern.getX(),
      (int) pattern.getY());
  if (Float.isNaN(moduleSizeEst1)) {
    return moduleSizeEst2 / 7.0f;
  }
  if (Float.isNaN(moduleSizeEst2)) {
    return moduleSizeEst1 / 7.0f;
  }
  // Average them, and divide by 7 since we've counted the width of 3 black modules,
  // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
  return (moduleSizeEst1 + moduleSizeEst2) / 14.0f;
}
 
Example #19
Source File: ByQuadrantReader.java    From weex with Apache License 2.0 5 votes vote down vote up
private static void makeAbsolute(ResultPoint[] points, int leftOffset, int topOffset) {
  if (points != null) {
    for (int i = 0; i < points.length; i++) {
      ResultPoint relative = points[i];
      points[i] = new ResultPoint(relative.getX() + leftOffset, relative.getY() + topOffset);
    }
  }
}
 
Example #20
Source File: WhiteRectangleDetector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private ResultPoint getBlackPointOnSegment(float aX, float aY, float bX, float bY) {
  int dist = MathUtils.round(MathUtils.distance(aX, aY, bX, bY));
  float xStep = (bX - aX) / dist;
  float yStep = (bY - aY) / dist;

  for (int i = 0; i < dist; i++) {
    int x = MathUtils.round(aX + i * xStep);
    int y = MathUtils.round(aY + i * yStep);
    if (image.get(x, y)) {
      return new ResultPoint(x, y);
    }
  }
  return null;
}
 
Example #21
Source File: BoundingBox.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
BoundingBox(BitMatrix image,
            ResultPoint topLeft,
            ResultPoint bottomLeft,
            ResultPoint topRight,
            ResultPoint bottomRight) throws NotFoundException {
  if ((topLeft == null && topRight == null) ||
      (bottomLeft == null && bottomRight == null) ||
      (topLeft != null && bottomLeft == null) ||
      (topRight != null && bottomRight == null)) {
    throw NotFoundException.getNotFoundInstance();
  }
  init(image, topLeft, bottomLeft, topRight, bottomRight);
}
 
Example #22
Source File: MonochromeRectangleDetector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Detects a rectangular region of black and white -- mostly black -- with a region of mostly
 * white, in an image.</p>
 *
 * @return {@link ResultPoint}[] describing the corners of the rectangular region. The first and
 *  last points are opposed on the diagonal, as are the second and third. The first point will be
 *  the topmost point and the last, the bottommost. The second point will be leftmost and the
 *  third, the rightmost
 * @throws NotFoundException if no Data Matrix Code can be found
 */
public ResultPoint[] detect() throws NotFoundException {
  int height = image.getHeight();
  int width = image.getWidth();
  int halfHeight = height / 2;
  int halfWidth = width / 2;
  int deltaY = Math.max(1, height / (MAX_MODULES * 8));
  int deltaX = Math.max(1, width / (MAX_MODULES * 8));

  int top = 0;
  int bottom = height;
  int left = 0;
  int right = width;
  ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right,
      halfHeight, -deltaY, top, bottom, halfWidth / 2);
  top = (int) pointA.getY() - 1;
  ResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right,
      halfHeight, 0, top, bottom, halfHeight / 2);
  left = (int) pointB.getX() - 1;
  ResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right,
      halfHeight, 0, top, bottom, halfHeight / 2);
  right = (int) pointC.getX() + 1;
  ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right,
      halfHeight, deltaY, top, bottom, halfWidth / 2);
  bottom = (int) pointD.getY() + 1;

  // Go try to find point A again with better information -- might have been off at first.
  pointA = findCornerFromCenter(halfWidth, 0, left, right,
      halfHeight, -deltaY, top, bottom, halfWidth / 4);

  return new ResultPoint[] { pointA, pointB, pointC, pointD };
}
 
Example #23
Source File: WhiteRectangleDetector.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * recenters the points of a constant distance towards the center
 *
 * @param y bottom most point
 * @param z left most point
 * @param x right most point
 * @param t top most point
 * @return {@link ResultPoint}[] describing the corners of the rectangular
 *         region. The first and last points are opposed on the diagonal, as
 *         are the second and third. The first point will be the topmost
 *         point and the last, the bottommost. The second point will be
 *         leftmost and the third, the rightmost
 */
private ResultPoint[] centerEdges(ResultPoint y, ResultPoint z,
                                  ResultPoint x, ResultPoint t) {

  //
  //       t            t
  //  z                      x
  //        x    OR    z
  //   y                    y
  //

  float yi = y.getX();
  float yj = y.getY();
  float zi = z.getX();
  float zj = z.getY();
  float xi = x.getX();
  float xj = x.getY();
  float ti = t.getX();
  float tj = t.getY();

  if (yi < width / 2.0f) {
    return new ResultPoint[]{
        new ResultPoint(ti - CORR, tj + CORR),
        new ResultPoint(zi + CORR, zj + CORR),
        new ResultPoint(xi - CORR, xj - CORR),
        new ResultPoint(yi + CORR, yj - CORR)};
  } else {
    return new ResultPoint[]{
        new ResultPoint(ti + CORR, tj + CORR),
        new ResultPoint(zi + CORR, zj - CORR),
        new ResultPoint(xi - CORR, xj + CORR),
        new ResultPoint(yi - CORR, yj - CORR)};
  }
}
 
Example #24
Source File: QRCodeReader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  ResultPoint[] points;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
    decoderResult = decoder.decode(detectorResult.getBits(), hints);
    points = detectorResult.getPoints();
  }

  // If the code was mirrored: swap the bottom-left and the top-right points.
  if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
    ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
  }

  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
  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);
  }
  if (decoderResult.hasStructuredAppend()) {
    result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
                       decoderResult.getStructuredAppendSequenceNumber());
    result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
                       decoderResult.getStructuredAppendParity());
  }
  return result;
}
 
Example #25
Source File: WhiteRectangleDetector.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
/**
 * recenters the points of a constant distance towards the center
 *
 * @param y bottom most point
 * @param z left most point
 * @param x right most point
 * @param t top most point
 * @return {@link ResultPoint}[] describing the corners of the rectangular
 *         region. The first and last points are opposed on the diagonal, as
 *         are the second and third. The first point will be the topmost
 *         point and the last, the bottommost. The second point will be
 *         leftmost and the third, the rightmost
 */
private ResultPoint[] centerEdges(ResultPoint y, ResultPoint z,
                                  ResultPoint x, ResultPoint t) {

  //
  //       t            t
  //  z                      x
  //        x    OR    z
  //   y                    y
  //

  float yi = y.getX();
  float yj = y.getY();
  float zi = z.getX();
  float zj = z.getY();
  float xi = x.getX();
  float xj = x.getY();
  float ti = t.getX();
  float tj = t.getY();

  if (yi < width / 2.0f) {
    return new ResultPoint[]{
        new ResultPoint(ti - CORR, tj + CORR),
        new ResultPoint(zi + CORR, zj + CORR),
        new ResultPoint(xi - CORR, xj - CORR),
        new ResultPoint(yi + CORR, yj - CORR)};
  } else {
    return new ResultPoint[]{
        new ResultPoint(ti + CORR, tj + CORR),
        new ResultPoint(zi + CORR, zj - CORR),
        new ResultPoint(xi - CORR, xj + CORR),
        new ResultPoint(yi - CORR, yj - CORR)};
  }
}
 
Example #26
Source File: Detector.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private ResultPoint a(ResultPoint resultpoint, ResultPoint resultpoint1, ResultPoint resultpoint2, ResultPoint resultpoint3, int i)
    {
        ResultPoint resultpoint4;
        ResultPoint resultpoint5;
        float f = (float)a(resultpoint, resultpoint1) / (float)i;
        int j = a(resultpoint2, resultpoint3);
        float f1 = (resultpoint3.getX() - resultpoint2.getX()) / (float)j;
        float f2 = (resultpoint3.getY() - resultpoint2.getY()) / (float)j;
        resultpoint4 = new ResultPoint(resultpoint3.getX() + f1 * f, resultpoint3.getY() + f * f2);
        float f3 = (float)a(resultpoint, resultpoint1) / (float)i;
        int k = a(resultpoint1, resultpoint3);
        float f4 = (resultpoint3.getX() - resultpoint1.getX()) / (float)k;
        float f5 = (resultpoint3.getY() - resultpoint1.getY()) / (float)k;
        resultpoint5 = new ResultPoint(resultpoint3.getX() + f4 * f3, resultpoint3.getY() + f3 * f5);
        if (a(resultpoint4)) goto _L2; else goto _L1
_L1:
        if (!a(resultpoint5)) goto _L4; else goto _L3
_L3:
        resultpoint4 = resultpoint5;
_L6:
        return resultpoint4;
_L4:
        return null;
_L2:
        if (a(resultpoint5) && Math.abs(b(resultpoint2, resultpoint4).c() - b(resultpoint1, resultpoint4).c()) > Math.abs(b(resultpoint2, resultpoint5).c() - b(resultpoint1, resultpoint5).c()))
        {
            return resultpoint5;
        }
        if (true) goto _L6; else goto _L5
_L5:
    }
 
Example #27
Source File: Detector.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #28
Source File: PDF417Reader.java    From weex with Apache License 2.0 5 votes vote down vote up
private static int getMinCodewordWidth(ResultPoint[] p) {
  return Math.min(
      Math.min(getMinWidth(p[0], p[4]), getMinWidth(p[6], p[2]) * PDF417Common.MODULES_IN_CODEWORD /
          PDF417Common.MODULES_IN_STOP_PATTERN),
      Math.min(getMinWidth(p[1], p[5]), getMinWidth(p[7], p[3]) * PDF417Common.MODULES_IN_CODEWORD /
          PDF417Common.MODULES_IN_STOP_PATTERN));
}
 
Example #29
Source File: ViewfinderView.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
public ViewfinderView(Context context, AttributeSet attrs) {
  super(context, attrs);

  // Initialize these once for performance rather than calling them every time in onDraw().
  paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  maskColor = 0x60000000; // Sorry about the constants embedded, but we aren't using R.java
  resultColor = 0xffffffff;
  laserColor = 0xffcc0000;
  resultPointColor = 0xc099cc00;
  scannerAlpha = 0;
  possibleResultPoints = new ArrayList<ResultPoint>(5);
  lastPossibleResultPoints = null;
}
 
Example #30
Source File: ViewfinderView.java    From android-apps with MIT License 5 votes vote down vote up
public ViewfinderView(Context context, AttributeSet attrs) {
  super(context, attrs);

  // Initialize these once for performance rather than calling them every time in onDraw().
  paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  Resources resources = getResources();
  maskColor = resources.getColor(R.color.viewfinder_mask);
  resultColor = resources.getColor(R.color.result_view);
  frameColor = resources.getColor(R.color.viewfinder_frame);
  laserColor = resources.getColor(R.color.viewfinder_laser);
  resultPointColor = resources.getColor(R.color.possible_result_points);
  scannerAlpha = 0;
  possibleResultPoints = new ArrayList<ResultPoint>(5);
  lastPossibleResultPoints = null;
}