use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.
the class BoundingBox method calculateMinMaxValues.
private void calculateMinMaxValues() {
if (topLeft == null) {
topLeft = new ResultPoint(0, topRight.getY());
bottomLeft = new ResultPoint(0, bottomRight.getY());
} else if (topRight == null) {
topRight = new ResultPoint(image.getWidth() - 1, topLeft.getY());
bottomRight = new ResultPoint(image.getWidth() - 1, bottomLeft.getY());
}
minX = (int) Math.min(topLeft.getX(), bottomLeft.getX());
maxX = (int) Math.max(topRight.getX(), bottomRight.getX());
minY = (int) Math.min(topLeft.getY(), topRight.getY());
maxY = (int) Math.max(bottomLeft.getY(), bottomRight.getY());
}
use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.
the class BoundingBox method addMissingRows.
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);
}
use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.
the class Detector method correctTopRightRectangular.
/**
* 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;
}
use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.
the class QRCodeDecoderMetaData method applyMirroredCorrection.
/**
* Apply the result points' order correction due to mirroring.
*
* @param points Array of points to apply mirror correction to.
*/
public void applyMirroredCorrection(ResultPoint[] points) {
if (!mirrored || points == null || points.length < 3) {
return;
}
ResultPoint bottomLeft = points[0];
points[0] = points[2];
points[2] = bottomLeft;
// No need to 'fix' top-left and alignment pattern.
}
use of com.google.zxing.ResultPoint in project android-zxing by PearceXu.
the class Detector method computeDimension.
/**
* <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(// mod 4
dimension & 0x03) {
case 0:
dimension++;
break;
// 1? do nothing
case 2:
dimension--;
break;
case 3:
throw NotFoundException.getNotFoundInstance();
}
return dimension;
}
Aggregations