Java Code Examples for com.google.zxing.common.detector.MathUtils#round()

The following examples show how to use com.google.zxing.common.detector.MathUtils#round() . 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 Tesseract-OCR-Scanner 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 2
Source File: Detector.java    From reacteu-app with MIT License 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) >> 1) + 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 3
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 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 4
Source File: Detector.java    From RipplePower 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 5
Source File: Detector.java    From Telegram-FOSS with GNU General Public License v2.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:
      dimension += 2;
      break;
  }
  return dimension;
}
 
Example 6
Source File: Detector.java    From 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: 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 8
Source File: Detector.java    From Telegram with GNU General Public License v2.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:
      dimension += 2;
      break;
  }
  return dimension;
}
 
Example 9
Source File: Detector.java    From ZXing-Orient 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 10
Source File: Detector.java    From QrCodeScanner with GNU General Public License v3.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 11
Source File: Detector.java    From ScreenCapture with MIT License 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 12
Source File: Detector.java    From reacteu-app with MIT License 5 votes vote down vote up
/**
 *
 * <p>Gets the Aztec code corners from the bull's eye corners and the parameters </p>
 *
 * @param bullEyeCornerPoints the array of bull's eye corners
 * @return the array of aztec code corners
 * @throws NotFoundException if the corner points do not fit in the image
 */
private ResultPoint[] getMatrixCornerPoints(Point[] bullEyeCornerPoints) throws NotFoundException {

  float ratio = (2 * nbLayers + (nbLayers > 4 ? 1 : 0) + (nbLayers - 4) / 8)
      / (2.0f * nbCenterLayers);

  int dx = bullEyeCornerPoints[0].x-bullEyeCornerPoints[2].x;
  dx+=dx>0?1:-1;
  int dy = bullEyeCornerPoints[0].y-bullEyeCornerPoints[2].y;
  dy+=dy>0?1:-1;
  
  int targetcx = MathUtils.round(bullEyeCornerPoints[2].x - ratio * dx);
  int targetcy = MathUtils.round(bullEyeCornerPoints[2].y - ratio * dy);
  
  int targetax = MathUtils.round(bullEyeCornerPoints[0].x + ratio * dx);
  int targetay = MathUtils.round(bullEyeCornerPoints[0].y + ratio * dy);
  
  dx = bullEyeCornerPoints[1].x-bullEyeCornerPoints[3].x;
  dx+=dx>0?1:-1;
  dy = bullEyeCornerPoints[1].y-bullEyeCornerPoints[3].y;
  dy+=dy>0?1:-1;
  
  int targetdx = MathUtils.round(bullEyeCornerPoints[3].x - ratio * dx);
  int targetdy = MathUtils.round(bullEyeCornerPoints[3].y - ratio * dy);
  int targetbx = MathUtils.round(bullEyeCornerPoints[1].x + ratio * dx);
  int targetby = MathUtils.round(bullEyeCornerPoints[1].y+ratio*dy);
  
  if (!isValid(targetax, targetay) || !isValid(targetbx, targetby) || !isValid(targetcx, targetcy) || !isValid(targetdx, targetdy)) {
    throw NotFoundException.getNotFoundInstance();
  }
  
  return new ResultPoint[]{new ResultPoint(targetax, targetay), new ResultPoint(targetbx, targetby), new ResultPoint(targetcx, targetcy), new ResultPoint(targetdx, targetdy)}; 
}
 
Example 13
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
private boolean isValid(ResultPoint point) {
  int x = MathUtils.round(point.getX());
  int y = MathUtils.round(point.getY());
  return isValid(x, y);
}
 
Example 14
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
private static int distance(ResultPoint a, ResultPoint b) {
  return MathUtils.round(ResultPoint.distance(a, b));
}
 
Example 15
Source File: Detector.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
private static int distance(ResultPoint a, ResultPoint b) {
	return MathUtils.round(ResultPoint.distance(a, b));
}
 
Example 16
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private boolean isValid(ResultPoint point) {
  int x = MathUtils.round(point.getX());
  int y = MathUtils.round(point.getY());
  return isValid(x, y);
}
 
Example 17
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private static int distance(ResultPoint a, ResultPoint b) {
  return MathUtils.round(ResultPoint.distance(a, b));
}
 
Example 18
Source File: Detector.java    From reacteu-app with MIT License 4 votes vote down vote up
private static int distance(ResultPoint a, ResultPoint b) {
  return MathUtils.round(ResultPoint.distance(a, b));
}
 
Example 19
Source File: Detector.java    From reacteu-app with MIT License 4 votes vote down vote up
/**
 * 
 * <p> Finds the corners of a bull-eye centered on the passed point </p>
 * 
 * @param pCenter Center point
 * @return The corners of the bull-eye
 * @throws NotFoundException If no valid bull-eye can be found
 */
private Point[] getBullEyeCornerPoints(Point pCenter) throws NotFoundException {
  
  Point pina = pCenter;
  Point pinb = pCenter;
  Point pinc = pCenter;
  Point pind = pCenter;

  boolean color = true;
  
  for (nbCenterLayers = 1; nbCenterLayers < 9; nbCenterLayers++) {
    Point pouta = getFirstDifferent(pina, color, 1, -1);
    Point poutb = getFirstDifferent(pinb, color, 1, 1);
    Point poutc = getFirstDifferent(pinc, color, -1, 1);
    Point poutd = getFirstDifferent(pind, color, -1, -1);

    //d      a
    //
    //c      b

    if (nbCenterLayers>2) {
      float q = distance(poutd, pouta)*nbCenterLayers/(distance(pind, pina)*(nbCenterLayers+2));
      if ( q < 0.75 || q > 1.25 || !isWhiteOrBlackRectangle(pouta, poutb, poutc, poutd)) {
        break;
      }
    }

    pina = pouta;
    pinb = poutb;
    pinc = poutc;
    pind = poutd;

    color = !color;
  }

  if (nbCenterLayers != 5 && nbCenterLayers != 7) {
    throw NotFoundException.getNotFoundInstance();
  }
  
  compact = nbCenterLayers==5;
  
  float ratio = 0.75f*2/(2*nbCenterLayers-3);
  
  int dx = pina.x-pinc.x;
  int dy = pina.y-pinc.y;
  int targetcx = MathUtils.round(pinc.x-ratio*dx);
  int targetcy = MathUtils.round(pinc.y-ratio*dy);
  int targetax = MathUtils.round(pina.x+ratio*dx);
  int targetay = MathUtils.round(pina.y+ratio*dy);
  
  dx = pinb.x-pind.x;
  dy = pinb.y-pind.y;
  
  int targetdx = MathUtils.round(pind.x-ratio*dx);
  int targetdy = MathUtils.round(pind.y-ratio*dy);
  int targetbx = MathUtils.round(pinb.x+ratio*dx);
  int targetby = MathUtils.round(pinb.y+ratio*dy);
  
  if (!isValid(targetax, targetay) || !isValid(targetbx, targetby)
      || !isValid(targetcx, targetcy) || !isValid(targetdx, targetdy)) {
    throw NotFoundException.getNotFoundInstance();
  }
  
  Point pa = new Point(targetax,targetay);
  Point pb = new Point(targetbx,targetby);
  Point pc = new Point(targetcx,targetcy);
  Point pd = new Point(targetdx,targetdy);
  
  return new Point[]{pa, pb, pc, pd};
}
 
Example 20
Source File: Detector.java    From reacteu-app with MIT License 3 votes vote down vote up
/**
 * Computes the dimension (number of modules in a row) of the PDF417 Code
 * based on vertices of the codeword area and estimated module size.
 *
 * @param topLeft     of codeword area
 * @param topRight    of codeword area
 * @param bottomLeft  of codeword area
 * @param bottomRight of codeword are
 * @param moduleWidth estimated module size
 * @return the number of modules in a row.
 */
private static int computeDimension(ResultPoint topLeft,
                                    ResultPoint topRight,
                                    ResultPoint bottomLeft,
                                    ResultPoint bottomRight,
                                    float moduleWidth) {
  int topRowDimension = MathUtils.round(ResultPoint.distance(topLeft, topRight) / moduleWidth);
  int bottomRowDimension = MathUtils.round(ResultPoint.distance(bottomLeft, bottomRight) / moduleWidth);
  return ((((topRowDimension + bottomRowDimension) >> 1) + 8) / 17) * 17;
}