Detector.java (zxing-zxing-3.4.1) | : | Detector.java (zxing-zxing-3.5.0) | ||
---|---|---|---|---|
skipping to change at line 69 | skipping to change at line 69 | |||
return detect(false); | return detect(false); | |||
} | } | |||
/** | /** | |||
* Detects an Aztec Code in an image. | * Detects an Aztec Code in an image. | |||
* | * | |||
* @param isMirror if true, image is a mirror-image of original | * @param isMirror if true, image is a mirror-image of original | |||
* @return {@link AztecDetectorResult} encapsulating results of detecting an A ztec Code | * @return {@link AztecDetectorResult} encapsulating results of detecting an A ztec Code | |||
* @throws NotFoundException if no Aztec Code can be found | * @throws NotFoundException if no Aztec Code can be found | |||
*/ | */ | |||
public AztecDetectorResult detect(boolean isMirror) throws NotFoundException { | public AztecDetectorResult detect(boolean isMirror) throws NotFoundException { | |||
// 1. Get the center of the aztec matrix | // 1. Get the center of the aztec matrix | |||
Point pCenter = getMatrixCenter(); | Point pCenter = getMatrixCenter(); | |||
// 2. Get the center points of the four diagonal points just outside the bul l's eye | // 2. Get the center points of the four diagonal points just outside the bul l's eye | |||
// [topRight, bottomRight, bottomLeft, topLeft] | // [topRight, bottomRight, bottomLeft, topLeft] | |||
ResultPoint[] bullsEyeCorners = getBullsEyeCorners(pCenter); | ResultPoint[] bullsEyeCorners = getBullsEyeCorners(pCenter); | |||
if (isMirror) { | if (isMirror) { | |||
ResultPoint temp = bullsEyeCorners[0]; | ResultPoint temp = bullsEyeCorners[0]; | |||
skipping to change at line 428 | skipping to change at line 428 | |||
* @return true if the border of the rectangle passed in parameter is compound of white points only | * @return true if the border of the rectangle passed in parameter is compound of white points only | |||
* or black points only | * or black points only | |||
*/ | */ | |||
private boolean isWhiteOrBlackRectangle(Point p1, | private boolean isWhiteOrBlackRectangle(Point p1, | |||
Point p2, | Point p2, | |||
Point p3, | Point p3, | |||
Point p4) { | Point p4) { | |||
int corr = 3; | int corr = 3; | |||
p1 = new Point(p1.getX() - corr, p1.getY() + corr); | p1 = new Point(Math.max(0, p1.getX() - corr), Math.min(image.getHeight() - 1 | |||
p2 = new Point(p2.getX() - corr, p2.getY() - corr); | , p1.getY() + corr)); | |||
p3 = new Point(p3.getX() + corr, p3.getY() - corr); | p2 = new Point(Math.max(0, p2.getX() - corr), Math.max(0, p2.getY() - corr)) | |||
p4 = new Point(p4.getX() + corr, p4.getY() + corr); | ; | |||
p3 = new Point(Math.min(image.getWidth() - 1, p3.getX() + corr), | ||||
Math.max(0, Math.min(image.getHeight() - 1, p3.getY() - corr) | ||||
)); | ||||
p4 = new Point(Math.min(image.getWidth() - 1, p4.getX() + corr), | ||||
Math.min(image.getHeight() - 1, p4.getY() + corr)); | ||||
int cInit = getColor(p4, p1); | int cInit = getColor(p4, p1); | |||
if (cInit == 0) { | if (cInit == 0) { | |||
return false; | return false; | |||
} | } | |||
int c = getColor(p1, p2); | int c = getColor(p1, p2); | |||
if (c != cInit) { | if (c != cInit) { | |||
skipping to change at line 464 | skipping to change at line 466 | |||
} | } | |||
/** | /** | |||
* Gets the color of a segment | * Gets the color of a segment | |||
* | * | |||
* @return 1 if segment more than 90% black, -1 if segment is more than 90% wh ite, 0 else | * @return 1 if segment more than 90% black, -1 if segment is more than 90% wh ite, 0 else | |||
*/ | */ | |||
private int getColor(Point p1, Point p2) { | private int getColor(Point p1, Point p2) { | |||
float d = distance(p1, p2); | float d = distance(p1, p2); | |||
if (d == 0.0f) { | ||||
return 0; | ||||
} | ||||
float dx = (p2.getX() - p1.getX()) / d; | float dx = (p2.getX() - p1.getX()) / d; | |||
float dy = (p2.getY() - p1.getY()) / d; | float dy = (p2.getY() - p1.getY()) / d; | |||
int error = 0; | int error = 0; | |||
float px = p1.getX(); | float px = p1.getX(); | |||
float py = p1.getY(); | float py = p1.getY(); | |||
boolean colorModel = image.get(p1.getX(), p1.getY()); | boolean colorModel = image.get(p1.getX(), p1.getY()); | |||
int iMax = (int) Math.ceil(d); | int iMax = (int) Math.floor(d); | |||
for (int i = 0; i < iMax; i++) { | for (int i = 0; i < iMax; i++) { | |||
px += dx; | ||||
py += dy; | ||||
if (image.get(MathUtils.round(px), MathUtils.round(py)) != colorModel) { | if (image.get(MathUtils.round(px), MathUtils.round(py)) != colorModel) { | |||
error++; | error++; | |||
} | } | |||
px += dx; | ||||
py += dy; | ||||
} | } | |||
float errRatio = error / d; | float errRatio = error / d; | |||
if (errRatio > 0.1f && errRatio < 0.9f) { | if (errRatio > 0.1f && errRatio < 0.9f) { | |||
return 0; | return 0; | |||
} | } | |||
return (errRatio <= 0.1f) == colorModel ? 1 : -1; | return (errRatio <= 0.1f) == colorModel ? 1 : -1; | |||
} | } | |||
skipping to change at line 548 | skipping to change at line 553 | |||
dy = cornerPoints[1].getY() - cornerPoints[3].getY(); | dy = cornerPoints[1].getY() - cornerPoints[3].getY(); | |||
centerx = (cornerPoints[1].getX() + cornerPoints[3].getX()) / 2.0f; | centerx = (cornerPoints[1].getX() + cornerPoints[3].getX()) / 2.0f; | |||
centery = (cornerPoints[1].getY() + cornerPoints[3].getY()) / 2.0f; | centery = (cornerPoints[1].getY() + cornerPoints[3].getY()) / 2.0f; | |||
ResultPoint result1 = new ResultPoint(centerx + ratio * dx, centery + ratio * dy); | ResultPoint result1 = new ResultPoint(centerx + ratio * dx, centery + ratio * dy); | |||
ResultPoint result3 = new ResultPoint(centerx - ratio * dx, centery - ratio * dy); | ResultPoint result3 = new ResultPoint(centerx - ratio * dx, centery - ratio * dy); | |||
return new ResultPoint[]{result0, result1, result2, result3}; | return new ResultPoint[]{result0, result1, result2, result3}; | |||
} | } | |||
private boolean isValid(int x, int y) { | private boolean isValid(int x, int y) { | |||
return x >= 0 && x < image.getWidth() && y > 0 && y < image.getHeight(); | return x >= 0 && x < image.getWidth() && y >= 0 && y < image.getHeight(); | |||
} | } | |||
private boolean isValid(ResultPoint point) { | private boolean isValid(ResultPoint point) { | |||
int x = MathUtils.round(point.getX()); | int x = MathUtils.round(point.getX()); | |||
int y = MathUtils.round(point.getY()); | int y = MathUtils.round(point.getY()); | |||
return isValid(x, y); | return isValid(x, y); | |||
} | } | |||
private static float distance(Point a, Point b) { | private static float distance(Point a, Point b) { | |||
return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY()); | return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY()); | |||
} | } | |||
private static float distance(ResultPoint a, ResultPoint b) { | private static float distance(ResultPoint a, ResultPoint b) { | |||
return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY()); | return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY()); | |||
} | } | |||
private int getDimension() { | private int getDimension() { | |||
if (compact) { | if (compact) { | |||
return 4 * nbLayers + 11; | return 4 * nbLayers + 11; | |||
} | } | |||
if (nbLayers <= 4) { | return 4 * nbLayers + 2 * ((2 * nbLayers + 6) / 15) + 15; | |||
return 4 * nbLayers + 15; | ||||
} | ||||
return 4 * nbLayers + 2 * ((nbLayers - 4) / 8 + 1) + 15; | ||||
} | } | |||
static final class Point { | static final class Point { | |||
private final int x; | private final int x; | |||
private final int y; | private final int y; | |||
ResultPoint toResultPoint() { | ResultPoint toResultPoint() { | |||
return new ResultPoint(x, y); | return new ResultPoint(x, y); | |||
} | } | |||
End of changes. 8 change blocks. | ||||
13 lines changed or deleted | 18 lines changed or added |