コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x0"></param>
        /// <param name="y0"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="x3"></param>
        /// <param name="y3"></param>
        /// <param name="x0p"></param>
        /// <param name="y0p"></param>
        /// <param name="x1p"></param>
        /// <param name="y1p"></param>
        /// <param name="x2p"></param>
        /// <param name="y2p"></param>
        /// <param name="x3p"></param>
        /// <param name="y3p"></param>
        /// <returns></returns>
        public static PerspectiveTransform quadrilateralToQuadrilateral(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float x0p, float y0p, float x1p, float y1p, float x2p, float y2p, float x3p, float y3p)
        {
            PerspectiveTransform qToS = quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3);
            PerspectiveTransform sToQ = squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p);

            return(sToQ.times(qToS));
        }
コード例 #2
0
ファイル: Detector.cs プロジェクト: smart-make/zxing
        private static PerspectiveTransform createTransform(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, ResultPoint alignmentPattern, int dimension)
        {
            float dimMinusThree = (float)dimension - 3.5f;
            float bottomRightX;
            float bottomRightY;
            float sourceBottomRightX;
            float sourceBottomRightY;

            if (alignmentPattern != null)
            {
                bottomRightX       = alignmentPattern.X;
                bottomRightY       = alignmentPattern.Y;
                sourceBottomRightX = dimMinusThree - 3.0f;
                sourceBottomRightY = sourceBottomRightX;
            }
            else
            {
                // Don't have an alignment pattern, just make up the bottom-right point
                bottomRightX       = (topRight.X - topLeft.X) + bottomLeft.X;
                bottomRightY       = (topRight.Y - topLeft.Y) + bottomLeft.Y;
                sourceBottomRightX = dimMinusThree;
                sourceBottomRightY = dimMinusThree;
            }

            return(PerspectiveTransform.quadrilateralToQuadrilateral(3.5f, 3.5f, dimMinusThree, 3.5f, sourceBottomRightX, sourceBottomRightY, 3.5f, dimMinusThree, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRightX, bottomRightY, bottomLeft.X, bottomLeft.Y));
        }
コード例 #3
0
        /// <summary>
        /// </summary>
        /// <param name="image"></param>
        /// <param name="dimensionX"></param>
        /// <param name="dimensionY"></param>
        /// <param name="p1ToX"></param>
        /// <param name="p1ToY"></param>
        /// <param name="p2ToX"></param>
        /// <param name="p2ToY"></param>
        /// <param name="p3ToX"></param>
        /// <param name="p3ToY"></param>
        /// <param name="p4ToX"></param>
        /// <param name="p4ToY"></param>
        /// <param name="p1FromX"></param>
        /// <param name="p1FromY"></param>
        /// <param name="p2FromX"></param>
        /// <param name="p2FromY"></param>
        /// <param name="p3FromX"></param>
        /// <param name="p3FromY"></param>
        /// <param name="p4FromX"></param>
        /// <param name="p4FromY"></param>
        /// <returns></returns>
        public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, float p1ToX, float p1ToY, float p2ToX, float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY)
        {
            PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral(
                p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY,
                p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY);

            return(sampleGrid(image, dimensionX, dimensionY, transform));
        }
コード例 #4
0
ファイル: SongeUtil.cs プロジェクト: SongE1989/TradeGame
 PerspectiveTransform times(PerspectiveTransform other)
 {
     return(new PerspectiveTransform(a11 * other.a11 + a21 * other.a12 + a31 * other.a13,
                                     a11 * other.a21 + a21 * other.a22 + a31 * other.a23, a11 * other.a31 + a21 * other.a32 + a31
                                     * other.a33, a12 * other.a11 + a22 * other.a12 + a32 * other.a13, a12 * other.a21 + a22
                                     * other.a22 + a32 * other.a23, a12 * other.a31 + a22 * other.a32 + a32 * other.a33, a13
                                     * other.a11 + a23 * other.a12 + a33 * other.a13, a13 * other.a21 + a23 * other.a22 + a33
                                     * other.a23, a13 * other.a31 + a23 * other.a32 + a33 * other.a33));
 }
コード例 #5
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);
 }
コード例 #6
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);
 }
コード例 #7
0
        public void testSquareToQuadrilateral()
        {
            PerspectiveTransform pt = PerspectiveTransform.squareToQuadrilateral(
                2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f);

            assertPointEquals(2.0f, 3.0f, 0.0f, 0.0f, pt);
            assertPointEquals(10.0f, 4.0f, 1.0f, 0.0f, pt);
            assertPointEquals(4.0f, 9.0f, 0.0f, 1.0f, pt);
            assertPointEquals(16.0f, 15.0f, 1.0f, 1.0f, pt);
            assertPointEquals(6.535211f, 6.8873234f, 0.5f, 0.5f, pt);
            assertPointEquals(48.0f, 42.42857f, 1.5f, 1.5f, pt);
        }
コード例 #8
0
        public void testQuadrilateralToQuadrilateral()
        {
            PerspectiveTransform pt = PerspectiveTransform.quadrilateralToQuadrilateral(
                2.0f, 3.0f, 10.0f, 4.0f, 16.0f, 15.0f, 4.0f, 9.0f,
                103.0f, 110.0f, 300.0f, 120.0f, 290.0f, 270.0f, 150.0f, 280.0f);

            assertPointEquals(103.0f, 110.0f, 2.0f, 3.0f, pt);
            assertPointEquals(300.0f, 120.0f, 10.0f, 4.0f, pt);
            assertPointEquals(290.0f, 270.0f, 16.0f, 15.0f, pt);
            assertPointEquals(150.0f, 280.0f, 4.0f, 9.0f, pt);
            assertPointEquals(7.1516876f, -64.60185f, 0.5f, 0.5f, pt);
            assertPointEquals(328.09116f, 334.16385f, 50.0f, 50.0f, pt);
        }
コード例 #9
0
        public override BitMatrix sampleGrid(BitMatrix image, int dimension, PerspectiveTransform transform)
        {
            BitMatrix bits = new BitMatrix(dimension);

            float[] points = new float[dimension << 1];
            for (int y = 0; y < dimension; 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
                checkAndNudgePoints(image, points);
                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'"
                        if (image.get_Renamed((int)points[x], (int)points[x + 1]))
                        {
                            // Black(-ish) pixel
                            bits.set_Renamed(x >> 1, y);
                        }
                    }
                }
                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.
                    throw ReaderException.Instance;
                }
            }
            return(bits);
        }
コード例 #10
0
		public override BitMatrix sampleGrid(BitMatrix image, int dimension, PerspectiveTransform transform)
		{
			BitMatrix bits = new BitMatrix(dimension);
			float[] points = new float[dimension << 1];
			for (int y = 0; y < dimension; 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
				checkAndNudgePoints(image, points);
				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'"
						if (image.get_Renamed((int) points[x], (int) points[x + 1]))
						{
							// Black(-ish) pixel
							bits.set_Renamed(x >> 1, y);
						}
					}
				}
				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.
					throw ReaderException.Instance;
				}
			}
			return bits;
		}
コード例 #11
0
        private static PerspectiveTransform createTransform(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, ResultPoint alignmentPattern, int dimension)
        {
            //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 dimMinusThree = (float)dimension - 3.5f;
            float bottomRightX;
            float bottomRightY;
            float sourceBottomRightX;
            float sourceBottomRightY;

            if (alignmentPattern != null)
            {
                bottomRightX       = alignmentPattern.X;
                bottomRightY       = alignmentPattern.Y;
                sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f;
            }
            else
            {
                // Don't have an alignment pattern, just make up the bottom-right point
                bottomRightX       = (topRight.X - topLeft.X) + bottomLeft.X;
                bottomRightY       = (topRight.Y - topLeft.Y) + bottomLeft.Y;
                sourceBottomRightX = sourceBottomRightY = dimMinusThree;
            }

            return(PerspectiveTransform.quadrilateralToQuadrilateral(
                       3.5f,
                       3.5f,
                       dimMinusThree,
                       3.5f,
                       sourceBottomRightX,
                       sourceBottomRightY,
                       3.5f,
                       dimMinusThree,
                       topLeft.X,
                       topLeft.Y,
                       topRight.X,
                       topRight.Y,
                       bottomRightX,
                       bottomRightY,
                       bottomLeft.X,
                       bottomLeft.Y));
        }
コード例 #12
0
 public virtual BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform)
 {
     throw new System.NotSupportedException();
 }
コード例 #13
0
 internal PerspectiveTransform times(PerspectiveTransform other)
 {
    return new PerspectiveTransform(a11 * other.a11 + a21 * other.a12 + a31 * other.a13, 
       a11 * other.a21 + a21 * other.a22 + a31 * other.a23, 
       a11 * other.a31 + a21 * other.a32 + a31 * other.a33, 
       a12 * other.a11 + a22 * other.a12 + a32 * other.a13, 
       a12 * other.a21 + a22 * other.a22 + a32 * other.a23, 
       a12 * other.a31 + a22 * other.a32 + a32 * other.a33, 
       a13 * other.a11 + a23 * other.a12 + a33 * other.a13, 
       a13 * other.a21 + a23 * other.a22 + a33 * other.a23, 
       a13 * other.a31 + a23 * other.a32 + a33 * other.a33);
 }
コード例 #14
0
ファイル: GridSampler.cs プロジェクト: hydrayu/imobile-src
 /// <summary>
 /// sampleGrid()
 /// </summary>
 /// <param name="image"></param>
 /// <param name="dimensionX"></param>
 /// <param name="dimensionY"></param>
 /// <param name="transform"></param>
 /// <returns></returns>
 public virtual BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform)
 {
     throw new System.NotSupportedException();
 }
コード例 #15
0
        private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension)
        {
            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(image, dimension, dimension, transform));
        }
コード例 #16
0
        /// <summary>
        /// Processes the finder pattern info.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <returns></returns>
        protected internal virtual DetectorResult processFinderPatternInfo(FinderPatternInfo info)
        {
            FinderPattern topLeft    = info.TopLeft;
            FinderPattern topRight   = info.TopRight;
            FinderPattern bottomLeft = info.BottomLeft;

            float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);

            if (moduleSize < 1.0f)
            {
                return(null);
            }
            int dimension;

            if (!computeDimension(topLeft, topRight, bottomLeft, moduleSize, out dimension))
            {
                return(null);
            }
            Internal.Version provisionalVersion = Internal.Version.getProvisionalVersionForDimension(dimension);
            if (provisionalVersion == null)
            {
                return(null);
            }
            int modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7;

            AlignmentPattern alignmentPattern = null;

            // Anything above version 1 has an alignment pattern
            if (provisionalVersion.AlignmentPatternCenters.Length > 0)
            {
                // Guess where a "bottom right" finder pattern would have been
                float bottomRightX = topRight.X - topLeft.X + bottomLeft.X;
                float bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y;

                // Estimate that alignment pattern is closer by 3 modules
                // from "bottom right" to known top left location
                //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 correctionToTopLeft = 1.0f - 3.0f / (float)modulesBetweenFPCenters;
                //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'"
                int estAlignmentX = (int)(topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X));
                //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'"
                int estAlignmentY = (int)(topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y));

                // Kind of arbitrary -- expand search radius before giving up
                for (int i = 4; i <= 16; i <<= 1)
                {
                    alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, (float)i);
                    if (alignmentPattern == null)
                    {
                        continue;
                    }
                    break;
                }
                // If we didn't find alignment pattern... well try anyway without it
            }

            PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

            BitMatrix bits = sampleGrid(image, transform, dimension);

            if (bits == null)
            {
                return(null);
            }

            ResultPoint[] points;
            if (alignmentPattern == null)
            {
                points = new ResultPoint[] { bottomLeft, topLeft, topRight };
            }
            else
            {
                points = new ResultPoint[] { bottomLeft, topLeft, topRight, alignmentPattern };
            }
            return(new DetectorResult(bits, points));
        }
コード例 #17
0
 internal PerspectiveTransform times(PerspectiveTransform other)
 {
     return(new PerspectiveTransform(_a11 * other._a11 + _a21 * other._a12 + _a31 * other._a13, _a11 * other._a21 + _a21 * other._a22 + _a31 * other._a23, _a11 * other._a31 + _a21 * other._a32 + _a31 * other._a33, _a12 * other._a11 + _a22 * other._a12 + _a32 * other._a13, _a12 * other._a21 + _a22 * other._a22 + _a32 * other._a23, _a12 * other._a31 + _a22 * other._a32 + _a32 * other._a33, _a13 * other._a11 + _a23 * other._a12 + _a33 * other._a13, _a13 * other._a21 + _a23 * other._a22 + _a33 * other._a23, _a13 * other._a31 + _a23 * other._a32 + _a33 * other._a33));
 }
コード例 #18
0
		internal PerspectiveTransform times(PerspectiveTransform other)
		{
			return new PerspectiveTransform(_a11 * other._a11 + _a21 * other._a12 + _a31 * other._a13, _a11 * other._a21 + _a21 * other._a22 + _a31 * other._a23, _a11 * other._a31 + _a21 * other._a32 + _a31 * other._a33, _a12 * other._a11 + _a22 * other._a12 + _a32 * other._a13, _a12 * other._a21 + _a22 * other._a22 + _a32 * other._a23, _a12 * other._a31 + _a22 * other._a32 + _a32 * other._a33, _a13 * other._a11 + _a23 * other._a12 + _a33 * other._a13, _a13 * other._a21 + _a23 * other._a22 + _a33 * other._a23, _a13 * other._a31 + _a23 * other._a32 + _a33 * other._a33);
		}
コード例 #19
0
 internal PerspectiveTransform Times(PerspectiveTransform other)
 {
     return(new PerspectiveTransform((a11 * other.a11) + (a21 * other.a12) + (a31 * other.a13), (a11 * other.a21) + (a21 * other.a22) + (a31 * other.a23), (a11 * other.a31) + (a21 * other.a32) + (a31 * other.a33), (a12 * other.a11) + (a22 * other.a12) + (a32 * other.a13), (a12 * other.a21) + (a22 * other.a22) + (a32 * other.a23), (a12 * other.a31) + (a22 * other.a32) + (a32 * other.a33), (a13 * other.a11) + (a23 * other.a12) + (a33 * other.a13), (a13 * other.a21) + (a23 * other.a22) + (a33 * other.a23), (a13 * other.a31) + (a23 * other.a32) + (a33 * other.a33)));
 }
コード例 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="dimensionX"></param>
        /// <param name="dimensionY"></param>
        /// <param name="transform"></param>
        /// <returns></returns>
        public static 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);
        }
コード例 #21
0
ファイル: Detector.cs プロジェクト: hankhongyi/zxing_for_wp8
 private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension)
 {
     GridSampler sampler = GridSampler.Instance;
     return sampler.sampleGrid(image, dimension, transform);
 }
コード例 #22
0
ファイル: Detector.cs プロジェクト: smart-make/zxing
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected final com.google.zxing.common.DetectorResult processFinderPatternInfo(FinderPatternInfo info) throws com.google.zxing.NotFoundException, com.google.zxing.FormatException
        protected internal DetectorResult processFinderPatternInfo(FinderPatternInfo info)
        {
            FinderPattern topLeft    = info.TopLeft;
            FinderPattern topRight   = info.TopRight;
            FinderPattern bottomLeft = info.BottomLeft;

            float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);

            if (moduleSize < 1.0f)
            {
                throw NotFoundException.NotFoundInstance;
            }
            int     dimension               = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
            Version provisionalVersion      = Version.getProvisionalVersionForDimension(dimension);
            int     modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7;

            AlignmentPattern alignmentPattern = null;

            // Anything above version 1 has an alignment pattern
            if (provisionalVersion.AlignmentPatternCenters.Length > 0)
            {
                // Guess where a "bottom right" finder pattern would have been
                float bottomRightX = topRight.X - topLeft.X + bottomLeft.X;
                float bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y;

                // Estimate that alignment pattern is closer by 3 modules
                // from "bottom right" to known top left location
                float correctionToTopLeft = 1.0f - 3.0f / (float)modulesBetweenFPCenters;
                int   estAlignmentX       = (int)(topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X));
                int   estAlignmentY       = (int)(topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y));

                // Kind of arbitrary -- expand search radius before giving up
                for (int i = 4; i <= 16; i <<= 1)
                {
                    try
                    {
                        alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, (float)i);
                        break;
                    }
                    catch (NotFoundException re)
                    {
                        // try next round
                    }
                }
                // If we didn't find alignment pattern... well try anyway without it
            }

            PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension);

            BitMatrix bits = sampleGrid(image, transform, dimension);

            ResultPoint[] points;
            if (alignmentPattern == null)
            {
                points = new ResultPoint[] { bottomLeft, topLeft, topRight };
            }
            else
            {
                points = new ResultPoint[] { bottomLeft, topLeft, topRight, alignmentPattern };
            }
            return(new DetectorResult(bits, points));
        }