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

The following examples show how to use com.google.zxing.ResultPoint#getY() . 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 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 2
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: GenericMultipleBarcodeReader.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private static Result a(Result result, int i, int j)
{
    ResultPoint aresultpoint[] = result.getResultPoints();
    if (aresultpoint == null)
    {
        return result;
    }
    ResultPoint aresultpoint1[] = new ResultPoint[aresultpoint.length];
    for (int k = 0; k < aresultpoint.length; k++)
    {
        ResultPoint resultpoint = aresultpoint[k];
        aresultpoint1[k] = new ResultPoint(resultpoint.getX() + (float)i, resultpoint.getY() + (float)j);
    }

    return new Result(result.getText(), result.getRawBytes(), aresultpoint1, result.getBarcodeFormat());
}
 
Example 4
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 5
Source File: GenericMultipleBarcodeReader.java    From reacteu-app with MIT License 5 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];
    newResultPoints[i] = new ResultPoint(oldPoint.getX() + xOffset, oldPoint.getY() + yOffset);
  }
  return new Result(result.getText(), result.getRawBytes(), newResultPoints,
      result.getBarcodeFormat());
}
 
Example 6
Source File: WhiteRectangleDetector.java    From Telegram-FOSS with GNU General Public License v2.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 7
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex 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 8
Source File: ByQuadrantReader.java    From analyzer-of-android-for-Apache-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 9
Source File: ByQuadrantReader.java    From Telegram 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 10
Source File: MonochromeRectangleDetector.java    From 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: MonochromeRectangleDetector.java    From Telegram-FOSS 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 13
Source File: MonochromeRectangleDetector.java    From reacteu-app with MIT License 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 >> 1;
  int halfWidth = width >> 1;
  int deltaY = Math.max(1, height / (MAX_MODULES << 3));
  int deltaX = Math.max(1, width / (MAX_MODULES << 3));

  int top = 0;
  int bottom = height;
  int left = 0;
  int right = width;
  ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right,
      halfHeight, -deltaY, top, bottom, halfWidth >> 1);
  top = (int) pointA.getY() - 1;
  ResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right,
      halfHeight, 0, top, bottom, halfHeight >> 1);
  left = (int) pointB.getX() - 1;
  ResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right,
      halfHeight, 0, top, bottom, halfHeight >> 1);
  right = (int) pointC.getX() + 1;
  ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right,
      halfHeight, deltaY, top, bottom, halfWidth >> 1);
  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 >> 2);

  return new ResultPoint[] { pointA, pointB, pointC, pointD };
}
 
Example 14
Source File: WhiteRectangleDetector.java    From ScreenCapture 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 15
Source File: Detector.java    From weex with Apache License 2.0 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 16
Source File: GenericMultipleBarcodeReader.java    From Telegram-FOSS 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 17
Source File: GenericMultipleBarcodeReader.java    From ZXing-Orient with Apache License 2.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) {
    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
/**
 * 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 19
Source File: Detector.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
private BitMatrix a(BitMatrix bitmatrix, ResultPoint resultpoint, ResultPoint resultpoint1, ResultPoint resultpoint2, ResultPoint resultpoint3)
{
    int i;
    GridSampler gridsampler;
    float f1;
    float f2;
    float f3;
    float f4;
    float f5;
    float f6;
    float f7;
    float f8;
    float f9;
    float f10;
    float f11;
    float f12;
    if (b)
    {
        i = 11 + 4 * c;
    } else
    if (c <= 4)
    {
        i = 15 + 4 * c;
    } else
    {
        i = 15 + (4 * c + 2 * (1 + (-4 + c) / 8));
    }
    gridsampler = GridSampler.getInstance();
    f1 = (float)i - 0.5F;
    f2 = (float)i - 0.5F;
    f3 = (float)i - 0.5F;
    f4 = (float)i - 0.5F;
    f5 = resultpoint.getX();
    f6 = resultpoint.getY();
    f7 = resultpoint3.getX();
    f8 = resultpoint3.getY();
    f9 = resultpoint2.getX();
    f10 = resultpoint2.getY();
    f11 = resultpoint1.getX();
    f12 = resultpoint1.getY();
    return gridsampler.sampleGrid(bitmatrix, i, i, 0.5F, 0.5F, f1, 0.5F, f2, f3, 0.5F, f4, f5, f6, f7, f8, f9, f10, f11, f12);
}
 
Example 20
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());
}