public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform)
      {
         if (dimensionX <= 0 || dimensionY <= 0)
         {
            return null;
         }
         BitMatrix bits = new BitMatrix(dimensionX, dimensionY);
         float[] points = new float[dimensionX << 1];
         for (int y = 0; y < dimensionY; y++)
         {
            int max = points.Length;
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float iValue = (float)y + 0.5f;
            for (int x = 0; x < max; x += 2)
            {
               //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
               points[x] = (float)(x >> 1) + 0.5f;
               points[x + 1] = iValue;
            }
            transform.transformPoints(points);
            // Quick check to see if points transformed to something inside the image;
            // sufficient to check the endpoints
            if (!checkAndNudgePoints(image, points))
               return null;
            try
            {
               var imageWidth = image.Width;
               var imageHeight = image.Height;

               for (int x = 0; x < max; x += 2)
               {
                  var imagex = (int)points[x];
                  var imagey = (int)points[x + 1];

                  if (imagex < 0 || imagex >= imageWidth || imagey < 0 || imagey >= imageHeight)
                  {
                     return null;
                  }

                  bits[x >> 1, y] = image[imagex, imagey];
               }
            }
            catch (System.IndexOutOfRangeException)
            {
               // java version:
               // 
               // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting
               // transform gets "twisted" such that it maps a straight line of points to a set of points
               // whose endpoints are in bounds, but others are not. There is probably some mathematical
               // way to detect this about the transformation that I don't know yet.
               // This results in an ugly runtime exception despite our clever checks above -- can't have
               // that. We could check each point's coordinates but that feels duplicative. We settle for
               // catching and wrapping ArrayIndexOutOfBoundsException.
               return null;
            }
         }
         return bits;
      }
Esempio n. 2
0
 private static void assertPointEquals(float expectedX,
                                       float expectedY,
                                       float sourceX,
                                       float sourceY,
                                       PerspectiveTransform pt)
 {
     float[] points = { sourceX, sourceY };
     pt.transformPoints(points);
     Assert.AreEqual(expectedX, points[0], EPSILON);
     Assert.AreEqual(expectedY, points[1], EPSILON);
 }
Esempio n. 3
0
        /// <summary>
        /// sampleGrid()
        /// </summary>
        /// <param name="image"></param>
        /// <param name="dimensionX"></param>
        /// <param name="dimensionY"></param>
        /// <param name="transform"></param>
        /// <returns></returns>
        public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform)
        {
            if (dimensionX <= 0 || dimensionY <= 0)
            {
                return(null);
            }
            BitMatrix bits = new BitMatrix(dimensionX, dimensionY);

            float[] points = new float[dimensionX << 1];
            for (int y = 0; y < dimensionY; y++)
            {
                int max = points.Length;
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                float iValue = (float)y + 0.5f;
                for (int x = 0; x < max; x += 2)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    points[x]     = (float)(x >> 1) + 0.5f;
                    points[x + 1] = iValue;
                }
                transform.transformPoints(points);
                // Quick check to see if points transformed to something inside the image;
                // sufficient to check the endpoints
                if (!checkAndNudgePoints(image, points))
                {
                    return(null);
                }
                try
                {
                    for (int x = 0; x < max; x += 2)
                    {
                        //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                        bits[x >> 1, y] = image[(int)points[x], (int)points[x + 1]];
                    }
                }
                catch (System.IndexOutOfRangeException)
                {
                    // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting
                    // transform gets "twisted" such that it maps a straight line of points to a set of points
                    // whose endpoints are in bounds, but others are not. There is probably some mathematical
                    // way to detect this about the transformation that I don't know yet.
                    // This results in an ugly runtime exception despite our clever checks above -- can't have
                    // that. We could check each point's coordinates but that feels duplicative. We settle for
                    // catching and wrapping ArrayIndexOutOfBoundsException.
                    return(null);
                }
            }
            return(bits);
        }