com.google.zxing.common.PerspectiveTransform Java Examples

The following examples show how to use com.google.zxing.common.PerspectiveTransform. 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 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 #2
Source File: Detector.java    From barterli_android 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 = (float) 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: Detector.java    From RipplePower with Apache License 2.0 6 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 #4
Source File: Detector.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public static PerspectiveTransform createTransform(ResultPoint resultpoint, ResultPoint resultpoint1, ResultPoint resultpoint2, ResultPoint resultpoint3, int i)
{
    float f = (float)i - 3.5F;
    float f1;
    float f2;
    float f3;
    float f4;
    if (resultpoint3 != null)
    {
        f1 = resultpoint3.getX();
        f2 = resultpoint3.getY();
        f3 = f - 3F;
        f4 = f3;
    } else
    {
        f1 = (resultpoint1.getX() - resultpoint.getX()) + resultpoint2.getX();
        f2 = (resultpoint1.getY() - resultpoint.getY()) + resultpoint2.getY();
        f3 = f;
        f4 = f;
    }
    return PerspectiveTransform.quadrilateralToQuadrilateral(3.5F, 3.5F, f, 3.5F, f4, f3, 3.5F, f, resultpoint.getX(), resultpoint.getY(), resultpoint1.getX(), resultpoint1.getY(), f1, f2, resultpoint2.getX(), resultpoint2.getY());
}
 
Example #5
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #6
Source File: Detector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #7
Source File: Detector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #8
Source File: Detector.java    From reacteu-app with MIT License 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #9
Source File: Detector.java    From weex with Apache License 2.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #10
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #11
Source File: Detector.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #12
Source File: Detector.java    From ScreenCapture with MIT License 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #13
Source File: Detector.java    From QrCodeScanner with GNU General Public License v3.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #14
Source File: Detector.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image,
                                    PerspectiveTransform transform,
                                    int dimension) throws NotFoundException {

  GridSampler sampler = GridSampler.getInstance();
  return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #15
Source File: Detector.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
		throws NotFoundException, FormatException {

	FinderPattern topLeft = info.getTopLeft();
	FinderPattern topRight = info.getTopRight();
	FinderPattern bottomLeft = info.getBottomLeft();

	float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
	if (moduleSize < 1.0f) {
		throw NotFoundException.getNotFoundInstance();
	}
	int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
	Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
	int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

	AlignmentPattern alignmentPattern = null;
	// Anything above version 1 has an alignment pattern
	if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

		// Guess where a "bottom right" finder pattern would have been
		float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
		float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

		// Estimate that alignment pattern is closer by 3 modules
		// from "bottom right" to known top left location
		float correctionToTopLeft = 1.0f - 3.0f / (float) modulesBetweenFPCenters;
		int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
		int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

		// Kind of arbitrary -- expand search radius before giving up
		for (int i = 4; i <= 16; i <<= 1) {
			try {
				alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, (float) i);
				break;
			} catch (NotFoundException re) {
				// try next round
			}
		}
		// If we didn't find alignment pattern... well try anyway without it
	}

	PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

	BitMatrix bits = sampleGrid(image, transform, dimension);

	ResultPoint[] points;
	if (alignmentPattern == null) {
		points = new ResultPoint[] { bottomLeft, topLeft, topRight };
	} else {
		points = new ResultPoint[] { bottomLeft, topLeft, topRight, alignmentPattern };
	}
	return new DetectorResult(bits, points);
}
 
Example #16
Source File: Detector.java    From ScreenCapture 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 #17
Source File: Detector.java    From Telegram with GNU General Public License v2.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 #18
Source File: Detector.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
    throws NotFoundException, FormatException {

  FinderPattern topLeft = info.getTopLeft();
  FinderPattern topRight = info.getTopRight();
  FinderPattern bottomLeft = info.getBottomLeft();

  float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
  if (moduleSize < 1.0f) {
    throw NotFoundException.getNotFoundInstance();
  }
  int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
  Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
  int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

  AlignmentPattern alignmentPattern = null;
  // Anything above version 1 has an alignment pattern
  if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

    // Guess where a "bottom right" finder pattern would have been
    float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
    float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

    // Estimate that alignment pattern is closer by 3 modules
    // from "bottom right" to known top left location
    float correctionToTopLeft = 1.0f - 3.0f / modulesBetweenFPCenters;
    int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
    int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

    // Kind of arbitrary -- expand search radius before giving up
    for (int i = 4; i <= 16; i <<= 1) {
      try {
        alignmentPattern = findAlignmentInRegion(moduleSize,
            estAlignmentX,
            estAlignmentY,
            i);
        break;
      } catch (NotFoundException re) {
        // try next round
      }
    }
    // If we didn't find alignment pattern... well try anyway without it
  }

  PerspectiveTransform transform =
      createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

  BitMatrix bits = sampleGrid(image, transform, dimension);

  ResultPoint[] points;
  if (alignmentPattern == null) {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight};
  } else {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight, alignmentPattern};
  }
  return new DetectorResult(bits, points);
}
 
Example #19
Source File: Detector.java    From android-quick-response-code with Apache License 2.0 4 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension) throws NotFoundException {

        GridSampler sampler = GridSampler.getInstance();
        return sampler.sampleGrid(image, dimension, dimension, transform);
    }
 
Example #20
Source File: Detector.java    From android-quick-response-code with Apache License 2.0 4 votes vote down vote up
protected DetectorResult processFinderPatternInfo(FinderPatternInfo info) throws NotFoundException, FormatException {

        FinderPattern topLeft = info.getTopLeft();
        FinderPattern topRight = info.getTopRight();
        FinderPattern bottomLeft = info.getBottomLeft();

        float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
        if (moduleSize < 1.0f) {
            throw NotFoundException.getNotFoundInstance();
        }
        int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
        Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
        int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

        AlignmentPattern alignmentPattern = null;
        // Anything above version 1 has an alignment pattern
        if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

            // Guess where a "bottom right" finder pattern would have been
            float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
            float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

            // Estimate that alignment pattern is closer by 3 modules
            // from "bottom right" to known top left location
            float correctionToTopLeft = 1.0f - 3.0f / modulesBetweenFPCenters;
            int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
            int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

            // Kind of arbitrary -- expand search radius before giving up
            for (int i = 4; i <= 16; i <<= 1) {
                try {
                    alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, i);
                    break;
                } catch (NotFoundException re) {
                    // try next round
                }
            }
            // If we didn't find alignment pattern... well try anyway without it
        }

        PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

        BitMatrix bits = sampleGrid(image, transform, dimension);

        ResultPoint[] points;
        if (alignmentPattern == null) {
            points = new ResultPoint[] { bottomLeft, topLeft, topRight };
        } else {
            points = new ResultPoint[] { bottomLeft, topLeft, topRight, alignmentPattern };
        }
        return new DetectorResult(bits, points);
    }
 
Example #21
Source File: Detector.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension) throws NotFoundException {

        GridSampler sampler = GridSampler.getInstance();
        return sampler.sampleGrid(image, dimension, dimension, transform);
    }
 
Example #22
Source File: Detector.java    From Tesseract-OCR-Scanner with Apache License 2.0 4 votes vote down vote up
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
    throws NotFoundException, FormatException {

  FinderPattern topLeft = info.getTopLeft();
  FinderPattern topRight = info.getTopRight();
  FinderPattern bottomLeft = info.getBottomLeft();

  float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
  if (moduleSize < 1.0f) {
    throw NotFoundException.getNotFoundInstance();
  }
  int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
  Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
  int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

  AlignmentPattern alignmentPattern = null;
  // Anything above version 1 has an alignment pattern
  if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

    // Guess where a "bottom right" finder pattern would have been
    float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
    float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

    // Estimate that alignment pattern is closer by 3 modules
    // from "bottom right" to known top left location
    float correctionToTopLeft = 1.0f - 3.0f / modulesBetweenFPCenters;
    int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
    int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

    // Kind of arbitrary -- expand search radius before giving up
    for (int i = 4; i <= 16; i <<= 1) {
      try {
        alignmentPattern = findAlignmentInRegion(moduleSize,
            estAlignmentX,
            estAlignmentY,
            i);
        break;
      } catch (NotFoundException re) {
        // try next round
      }
    }
    // If we didn't find alignment pattern... well try anyway without it
  }

  PerspectiveTransform transform =
      createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

  BitMatrix bits = sampleGrid(image, transform, dimension);

  ResultPoint[] points;
  if (alignmentPattern == null) {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight};
  } else {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight, alignmentPattern};
  }
  return new DetectorResult(bits, points);
}
 
Example #23
Source File: Detector.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
protected DetectorResult processFinderPatternInfo(FinderPatternInfo info) throws NotFoundException, FormatException {

        FinderPattern topLeft = info.getTopLeft();
        FinderPattern topRight = info.getTopRight();
        FinderPattern bottomLeft = info.getBottomLeft();

        float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
        if (moduleSize < 1.0f) {
            throw NotFoundException.getNotFoundInstance();
        }
        int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
        Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
        int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

        AlignmentPattern alignmentPattern = null;
        // Anything above version 1 has an alignment pattern
        if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

            // Guess where a "bottom right" finder pattern would have been
            float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
            float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

            // Estimate that alignment pattern is closer by 3 modules
            // from "bottom right" to known top left location
            float correctionToTopLeft = 1.0f - 3.0f / (float) modulesBetweenFPCenters;
            int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
            int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

            // Kind of arbitrary -- expand search radius before giving up
            for (int i = 4; i <= 16; i <<= 1) {
                try {
                    alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, (float) i);
                    break;
                } catch (NotFoundException re) {
                    // try next round
                }
            }
            // If we didn't find alignment pattern... well try anyway without it
        }

        PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

        BitMatrix bits = sampleGrid(image, transform, dimension);

        ResultPoint[] points;
        if (alignmentPattern == null) {
            points = new ResultPoint[] { bottomLeft, topLeft, topRight };
        } else {
            points = new ResultPoint[] { bottomLeft, topLeft, topRight, alignmentPattern };
        }
        return new DetectorResult(bits, points);
    }
 
Example #24
Source File: Detector.java    From Tesseract-OCR-Scanner 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 = 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 #25
Source File: Detector.java    From Telegram-FOSS with GNU General Public License v2.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 #26
Source File: Detector.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
    throws NotFoundException, FormatException {

  FinderPattern topLeft = info.getTopLeft();
  FinderPattern topRight = info.getTopRight();
  FinderPattern bottomLeft = info.getBottomLeft();

  float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
  if (moduleSize < 1.0f) {
    throw NotFoundException.getNotFoundInstance();
  }
  int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
  Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
  int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

  AlignmentPattern alignmentPattern = null;
  // Anything above version 1 has an alignment pattern
  if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

    // Guess where a "bottom right" finder pattern would have been
    float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
    float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

    // Estimate that alignment pattern is closer by 3 modules
    // from "bottom right" to known top left location
    float correctionToTopLeft = 1.0f - 3.0f / modulesBetweenFPCenters;
    int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
    int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

    // Kind of arbitrary -- expand search radius before giving up
    for (int i = 4; i <= 16; i <<= 1) {
      try {
        alignmentPattern = findAlignmentInRegion(moduleSize,
            estAlignmentX,
            estAlignmentY,
            i);
        break;
      } catch (NotFoundException re) {
        // try next round
      }
    }
    // If we didn't find alignment pattern... well try anyway without it
  }

  PerspectiveTransform transform =
      createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

  BitMatrix bits = sampleGrid(image, transform, dimension);

  ResultPoint[] points;
  if (alignmentPattern == null) {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight};
  } else {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight, alignmentPattern};
  }
  return new DetectorResult(bits, points);
}
 
Example #27
Source File: Detector.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension)
		throws NotFoundException {

	GridSampler sampler = GridSampler.getInstance();
	return sampler.sampleGrid(image, dimension, dimension, transform);
}
 
Example #28
Source File: Detector.java    From ZXing-Orient 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 #29
Source File: Detector.java    From QrCodeScanner with GNU General Public License v3.0 4 votes vote down vote up
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
    throws NotFoundException, FormatException {

  FinderPattern topLeft = info.getTopLeft();
  FinderPattern topRight = info.getTopRight();
  FinderPattern bottomLeft = info.getBottomLeft();

  float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
  if (moduleSize < 1.0f) {
    throw NotFoundException.getNotFoundInstance();
  }
  int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
  Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
  int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;

  AlignmentPattern alignmentPattern = null;
  // Anything above version 1 has an alignment pattern
  if (provisionalVersion.getAlignmentPatternCenters().length > 0) {

    // Guess where a "bottom right" finder pattern would have been
    float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX();
    float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY();

    // Estimate that alignment pattern is closer by 3 modules
    // from "bottom right" to known top left location
    float correctionToTopLeft = 1.0f - 3.0f / modulesBetweenFPCenters;
    int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
    int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));

    // Kind of arbitrary -- expand search radius before giving up
    for (int i = 4; i <= 16; i <<= 1) {
      try {
        alignmentPattern = findAlignmentInRegion(moduleSize,
            estAlignmentX,
            estAlignmentY,
            i);
        break;
      } catch (NotFoundException re) {
        // try next round
      }
    }
    // If we didn't find alignment pattern... well try anyway without it
  }

  PerspectiveTransform transform =
      createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

  BitMatrix bits = sampleGrid(image, transform, dimension);

  ResultPoint[] points;
  if (alignmentPattern == null) {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight};
  } else {
    points = new ResultPoint[]{bottomLeft, topLeft, topRight, alignmentPattern};
  }
  return new DetectorResult(bits, points);
}
 
Example #30
Source File: Detector.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
private static BitMatrix a(BitMatrix bitmatrix, PerspectiveTransform perspectivetransform, int i)
{
    return GridSampler.getInstance().sampleGrid(bitmatrix, i, i, perspectivetransform);
}