Java Code Examples for com.google.zxing.ResultPoint#getX()

The following examples show how to use com.google.zxing.ResultPoint#getX() . 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: GenericMultipleBarcodeReader.java    From barcodescanner-lib-aar 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 2
Source File: GenericMultipleBarcodeReader.java    From QrCodeScanner with GNU General Public License v3.0 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 3
Source File: GenericMultipleBarcodeReader.java    From Telegram-FOSS with GNU General Public License v2.0 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 4
Source File: GenericMultipleBarcodeReader.java    From Tesseract-OCR-Scanner with Apache License 2.0 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 5
Source File: GenericMultipleBarcodeReader.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 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(), newResultPoints, result.getBarcodeFormat());
  newResult.putAllMetadata(result.getResultMetadata());
  return newResult;
}
 
Example 6
Source File: Detector.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the position of the white top right module using the output of
 * the rectangle detector for a square matrix
 */
private ResultPoint correctTopRight(ResultPoint bottomLeft, ResultPoint bottomRight, ResultPoint topLeft,
		ResultPoint topRight, int dimension) {

	float corr = distance(bottomLeft, bottomRight) / (float) dimension;
	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) dimension;
	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(transitionsBetween(topLeft, c1).getTransitions()
			- transitionsBetween(bottomRight, c1).getTransitions());
	int l2 = Math.abs(transitionsBetween(topLeft, c2).getTransitions()
			- transitionsBetween(bottomRight, c2).getTransitions());

	return l1 <= l2 ? c1 : c2;
}
 
Example 7
Source File: ByQuadrantReader.java    From Telegram-FOSS with GNU General Public License v2.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];
      if (relative != null) {
        points[i] = new ResultPoint(relative.getX() + leftOffset, relative.getY() + topOffset);
      }    
    }
  }
}
 
Example 8
Source File: Detector.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: MonochromeRectangleDetector.java    From Tesseract-OCR-Scanner with Apache License 2.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 10
Source File: MonochromeRectangleDetector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.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 11
Source File: MonochromeRectangleDetector.java    From RipplePower with Apache License 2.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 12
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 13
Source File: BoundingBox.java    From weex with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: Detector.java    From QrCodeScanner with GNU General Public License v3.0 4 votes vote down vote up
private 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 = dimMinusThree - 3.0f;
    sourceBottomRightY = sourceBottomRightX;
  } 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 = dimMinusThree;
    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 15
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private 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 = dimMinusThree - 3.0f;
    sourceBottomRightY = sourceBottomRightX;
  } 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 = dimMinusThree;
    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 16
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
private static PerspectiveTransform createTransform(ResultPoint topLeft,
                                                    ResultPoint topRight,
                                                    ResultPoint bottomLeft,
                                                    ResultPoint alignmentPattern,
                                                    int dimension) {
  float dimMinusThree = (float) dimension - 3.5f;
  float bottomRightX;
  float bottomRightY;
  float sourceBottomRightX;
  float sourceBottomRightY;
  if (alignmentPattern != null) {
    bottomRightX = alignmentPattern.getX();
    bottomRightY = alignmentPattern.getY();
    sourceBottomRightX = dimMinusThree - 3.0f;
    sourceBottomRightY = sourceBottomRightX;
  } 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 = dimMinusThree;
    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 17
Source File: GenericMultipleBarcodeReader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void doDecodeMultiple(BinaryBitmap image,
                              Map<DecodeHintType,?> hints,
                              List<Result> results,
                              int xOffset,
                              int yOffset,
                              int currentDepth) {
  if (currentDepth > MAX_DEPTH) {
    return;
  }

  Result result;
  try {
    result = delegate.decode(image, hints);
  } catch (ReaderException ignored) {
    return;
  }
  boolean alreadyFound = false;
  for (Result existingResult : results) {
    if (existingResult.getText().equals(result.getText())) {
      alreadyFound = true;
      break;
    }
  }
  if (!alreadyFound) {
    results.add(translateResultPoints(result, xOffset, yOffset));
  }
  ResultPoint[] resultPoints = result.getResultPoints();
  if (resultPoints == null || resultPoints.length == 0) {
    return;
  }
  int width = image.getWidth();
  int height = image.getHeight();
  float minX = width;
  float minY = height;
  float maxX = 0.0f;
  float maxY = 0.0f;
  for (ResultPoint point : resultPoints) {
    if (point == null) {
      continue;
    }
    float x = point.getX();
    float y = point.getY();
    if (x < minX) {
      minX = x;
    }
    if (y < minY) {
      minY = y;
    }
    if (x > maxX) {
      maxX = x;
    }
    if (y > maxY) {
      maxY = y;
    }
  }

  // Decode left of barcode
  if (minX > MIN_DIMENSION_TO_RECUR) {
    doDecodeMultiple(image.crop(0, 0, (int) minX, height),
                     hints, results,
                     xOffset, yOffset,
                     currentDepth + 1);
  }
  // Decode above barcode
  if (minY > MIN_DIMENSION_TO_RECUR) {
    doDecodeMultiple(image.crop(0, 0, width, (int) minY),
                     hints, results,
                     xOffset, yOffset,
                     currentDepth + 1);
  }
  // Decode right of barcode
  if (maxX < width - MIN_DIMENSION_TO_RECUR) {
    doDecodeMultiple(image.crop((int) maxX, 0, width - (int) maxX, height),
                     hints, results,
                     xOffset + (int) maxX, yOffset,
                     currentDepth + 1);
  }
  // Decode below barcode
  if (maxY < height - MIN_DIMENSION_TO_RECUR) {
    doDecodeMultiple(image.crop(0, (int) maxY, width, height - (int) maxY),
                     hints, results,
                     xOffset, yOffset + (int) maxY,
                     currentDepth + 1);
  }
}
 
Example 18
Source File: Detector.java    From ZXing-Orient with Apache License 2.0 4 votes vote down vote up
/**
 * Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
 */
private ResultPointsAndTransitions transitionsBetween(ResultPoint from, ResultPoint to) {
  // See QR Code Detector, sizeOfBlackWhiteBlackRun()
  int fromX = (int) from.getX();
  int fromY = (int) from.getY();
  int toX = (int) to.getX();
  int toY = (int) to.getY();
  boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);
  if (steep) {
    int temp = fromX;
    fromX = fromY;
    fromY = temp;
    temp = toX;
    toX = toY;
    toY = temp;
  }

  int dx = Math.abs(toX - fromX);
  int dy = Math.abs(toY - fromY);
  int error = -dx / 2;
  int ystep = fromY < toY ? 1 : -1;
  int xstep = fromX < toX ? 1 : -1;
  int transitions = 0;
  boolean inBlack = image.get(steep ? fromY : fromX, steep ? fromX : fromY);
  for (int x = fromX, y = fromY; x != toX; x += xstep) {
    boolean isBlack = image.get(steep ? y : x, steep ? x : y);
    if (isBlack != inBlack) {
      transitions++;
      inBlack = isBlack;
    }
    error += dy;
    if (error > 0) {
      if (y == toY) {
        break;
      }
      y += ystep;
      error -= dx;
    }
  }
  return new ResultPointsAndTransitions(from, to, transitions);
}
 
Example 19
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private boolean isValid(ResultPoint p) {
  return p.getX() >= 0 && p.getX() < image.getWidth() && p.getY() > 0 && p.getY() < image.getHeight();
}
 
Example 20
Source File: Detector.java    From weex with Apache License 2.0 4 votes vote down vote up
/**
 * Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
 */
private ResultPointsAndTransitions transitionsBetween(ResultPoint from, ResultPoint to) {
  // See QR Code Detector, sizeOfBlackWhiteBlackRun()
  int fromX = (int) from.getX();
  int fromY = (int) from.getY();
  int toX = (int) to.getX();
  int toY = (int) to.getY();
  boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);
  if (steep) {
    int temp = fromX;
    fromX = fromY;
    fromY = temp;
    temp = toX;
    toX = toY;
    toY = temp;
  }

  int dx = Math.abs(toX - fromX);
  int dy = Math.abs(toY - fromY);
  int error = -dx / 2;
  int ystep = fromY < toY ? 1 : -1;
  int xstep = fromX < toX ? 1 : -1;
  int transitions = 0;
  boolean inBlack = image.get(steep ? fromY : fromX, steep ? fromX : fromY);
  for (int x = fromX, y = fromY; x != toX; x += xstep) {
    boolean isBlack = image.get(steep ? y : x, steep ? x : y);
    if (isBlack != inBlack) {
      transitions++;
      inBlack = isBlack;
    }
    error += dy;
    if (error > 0) {
      if (y == toY) {
        break;
      }
      y += ystep;
      error -= dx;
    }
  }
  return new ResultPointsAndTransitions(from, to, transitions);
}