Better, still some bugs

git-svn-id: https://zxing.googlecode.com/svn/trunk@22 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2007-11-09 19:13:28 +00:00
parent 033ae10187
commit 703852e839
2 changed files with 40 additions and 29 deletions

View file

@ -74,9 +74,8 @@ public final class DefaultGridSampler extends GridSampler {
// Quick check to see if points transformed to something inside the image;
// sufficent to check the endpoints
checkEndpoint(image, points);
for (int j = 0; j < dimension; j++) {
int offset = j << 1;
if (image.isBlack((int) points[offset], (int) points[offset + 1])) {
for (int j = 0; j < max; j += 2) {
if (image.isBlack((int) points[j], (int) points[j + 1])) {
// Black(-ish) pixel
bits.set(i, j);
}

View file

@ -27,9 +27,9 @@ final class PerspectiveTransform {
private final float a11, a12, a13, a21, a22, a23, a31, a32, a33;
private PerspectiveTransform(float a11, float a12, float a13,
float a21, float a22, float a23,
float a31, float a32, float a33) {
private PerspectiveTransform(float a11, float a21, float a31,
float a12, float a22, float a32,
float a13, float a23, float a33) {
this.a11 = a11;
this.a12 = a12;
this.a13 = a13;
@ -49,16 +49,28 @@ final class PerspectiveTransform {
float x1p, float y1p,
float x2p, float y2p,
float x3p, float y3p) {
return quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3).times(
return
quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3).times(
squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p));
}
void transformPoints(float[] points) {
for (int i = 0; i < points.length; i += 2) {
int max = points.length;
float a11 = this.a11;
float a12 = this.a12;
float a13 = this.a13;
float a21 = this.a21;
float a22 = this.a22;
float a23 = this.a23;
float a31 = this.a31;
float a32 = this.a32;
float a33 = this.a33;
for (int i = 0; i < max; i += 2) {
float x = points[i];
float y = points[i+1];
points[i] = a11*x + a12*y + a13;
points[i+1] = a21*x + a22*y + a23;
float denominator = a13*x + a23*y + a33;
points[i] = (a11*x + a21*y + a31) / denominator;
points[i+1] = (a12*x + a22*y + a32) / denominator;
}
}
@ -76,15 +88,15 @@ final class PerspectiveTransform {
float a13 = (dx3*dy2 - dx2*dy3) / denominator;
float a23 = (dx1*dy3 - dx3*dy1) / denominator;
return new PerspectiveTransform(x1 - x0 + a13*x1,
y1 - y0 + a13*y1,
a13,
x3 - x0 + a23*x3,
y3 - y0 + a23*y3,
a23,
x0,
y0,
1.0f);
return new PerspectiveTransform(x1 - x0 + a13*x1,
x3 - x0 + a23*x3,
x0,
y1 - y0 + a13*y1,
y3 - y0 + a23*y3,
y0,
a13,
a23,
1.0f);
}
private static PerspectiveTransform quadrilateralToSquare(float x0, float y0,
@ -97,19 +109,19 @@ final class PerspectiveTransform {
private PerspectiveTransform buildAdjoint() {
// Adjoint is the transpose of the cofactor matrix:
return new PerspectiveTransform(a22*a33 - a23*a32,
a12*a33 - a13*a32,
a12*a23 - a13*a22,
a21*a33 - a23*a31,
a11*a33 - a13*a31,
a11*a23 - a13*a21,
a21*a32 - a22*a31,
a11*a32 - a12*a31,
a11*a22 - a12*a21);
return new PerspectiveTransform(a22*a33 - a23*a32,
a23*a31 - a21*a33,
a21*a32 - a22*a31,
a13*a32 - a12*a33,
a11*a33 - a13*a31,
a12*a31 - a11*a32,
a12*a23 - a13*a22,
a13*a21 - a11*a23,
a11*a22 - a12*a21);
}
private PerspectiveTransform times(PerspectiveTransform other) {
return new PerspectiveTransform(a11*other.a11 + a12*other.a21 + a13*other.a31,
return new PerspectiveTransform(a11*other.a11 + a21*other.a12 + a31*other.a13,
a11*other.a12 + a12*other.a22 + a13*other.a32,
a11*other.a13 + a12*other.a23 + a13*other.a33,
a21*other.a11 + a22*other.a21 + a23*other.a31,