Modified my skew correction code to also work upside down, meaning we now decode...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 8 Jul 2009 20:38:21 +0000 (20:38 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 8 Jul 2009 20:38:21 +0000 (20:38 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1016 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/pdf417/detector/Detector.java
core/test/src/com/google/zxing/pdf417/PDF417BlackBox2TestCase.java

index c4a09d6..5f20f3a 100644 (file)
@@ -84,6 +84,11 @@ public final class Detector {
     if (vertices == null) {
       // Maybe the image is rotated 180 degrees?
       vertices = findVertices180(matrix);
+      if (vertices != null) {
+        correctCodeWordVertices(vertices, true);
+      }
+    } else {
+      correctCodeWordVertices(vertices, false);
     }
 
     if (vertices != null) {
@@ -92,7 +97,6 @@ public final class Detector {
         throw ReaderException.getInstance();
       }
 
-      correctCodeWordVertices(vertices);
       int dimension = computeDimension(vertices[4], vertices[6],
           vertices[5], vertices[7], moduleWidth);
 
@@ -271,12 +275,13 @@ public final class Detector {
    * This method moves those points back onto the edges of the theoretically perfect bounding
    * quadrilateral if needed.
    *
-   * FIXME: Make this work for 180 degree rotation.
-   *
    * @param vertices The eight vertices located by findVertices().
    */
-  private static void correctCodeWordVertices(ResultPoint[] vertices) {
+  private static void correctCodeWordVertices(ResultPoint[] vertices, boolean upsideDown) {
     float skew = vertices[4].getY() - vertices[6].getY();
+    if (upsideDown) {
+      skew = -skew;
+    }
     if (skew > SKEW_THRESHOLD) {
       // Fix v4
       float length = vertices[4].getX() - vertices[0].getX();
@@ -294,6 +299,9 @@ public final class Detector {
     }
 
     skew = vertices[7].getY() - vertices[5].getY();
+    if (upsideDown) {
+      skew = -skew;
+    }
     if (skew > SKEW_THRESHOLD) {
       // Fix v5
       float length = vertices[5].getX() - vertices[1].getX();
index 83a9cd0..06c28e7 100644 (file)
@@ -34,7 +34,7 @@ public final class PDF417BlackBox2TestCase extends AbstractBlackBoxTestCase {
   public PDF417BlackBox2TestCase() {
     super("test/data/blackbox/pdf417-2", new MultiFormatReader(), BarcodeFormat.PDF417);
     addTest(11, 11, 0.0f);
-    addTest(9, 9, 180.0f);
+    addTest(12, 12, 180.0f);
   }
 
   @Override