use of com.google.zxing.ResultPoint in project zxing by zxing.
the class Detector method isValid.
private boolean isValid(ResultPoint point) {
int x = MathUtils.round(point.getX());
int y = MathUtils.round(point.getY());
return isValid(x, y);
}
use of com.google.zxing.ResultPoint in project zxing by zxing.
the class Detector method sampleGrid.
/**
* Creates a BitMatrix by sampling the provided image.
* topLeft, topRight, bottomRight, and bottomLeft are the centers of the squares on the
* diagonal just outside the bull's eye.
*/
private BitMatrix sampleGrid(BitMatrix image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomRight, ResultPoint bottomLeft) throws NotFoundException {
GridSampler sampler = GridSampler.getInstance();
int dimension = getDimension();
float low = dimension / 2.0f - nbCenterLayers;
float high = dimension / 2.0f + nbCenterLayers;
return sampler.sampleGrid(image, dimension, dimension, // topleft
low, // topleft
low, // topright
high, // topright
low, // bottomright
high, // bottomright
high, // bottomleft
low, // bottomleft
high, topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRight.getX(), bottomRight.getY(), bottomLeft.getX(), bottomLeft.getY());
}
use of com.google.zxing.ResultPoint in project zxing by zxing.
the class Detector method sampleLine.
/**
* 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;
}
use of com.google.zxing.ResultPoint in project zxing by zxing.
the class Detector method transitionsBetween.
/**
* Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
*/
private ResultPointsAndTransitions transitionsBetween(ResultPoint from, ResultPoint to) {
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
int fromX = (int) from.getX();
int fromY = (int) from.getY();
int toX = (int) to.getX();
int toY = (int) to.getY();
boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);
if (steep) {
int temp = fromX;
fromX = fromY;
fromY = temp;
temp = toX;
toX = toY;
toY = temp;
}
int dx = Math.abs(toX - fromX);
int dy = Math.abs(toY - fromY);
int error = -dx / 2;
int ystep = fromY < toY ? 1 : -1;
int xstep = fromX < toX ? 1 : -1;
int transitions = 0;
boolean inBlack = image.get(steep ? fromY : fromX, steep ? fromX : fromY);
for (int x = fromX, y = fromY; x != toX; x += xstep) {
boolean isBlack = image.get(steep ? y : x, steep ? x : y);
if (isBlack != inBlack) {
transitions++;
inBlack = isBlack;
}
error += dy;
if (error > 0) {
if (y == toY) {
break;
}
y += ystep;
error -= dx;
}
}
return new ResultPointsAndTransitions(from, to, transitions);
}
use of com.google.zxing.ResultPoint in project zxing by zxing.
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;
}
Aggregations