Esempio n. 1
0
        private static BitMatrix sampleGrid(BitMatrix image,
                                            ResultPoint topLeft,
                                            ResultPoint bottomLeft,
                                            ResultPoint bottomRight,
                                            ResultPoint topRight,
                                            int dimensionX,
                                            int dimensionY)
        {
            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(image,
                                      dimensionX,
                                      dimensionY,
                                      0.5f,
                                      0.5f,
                                      dimensionX - 0.5f,
                                      0.5f,
                                      dimensionX - 0.5f,
                                      dimensionY - 0.5f,
                                      0.5f,
                                      dimensionY - 0.5f,
                                      topLeft.X,
                                      topLeft.Y,
                                      topRight.X,
                                      topRight.Y,
                                      bottomRight.X,
                                      bottomRight.Y,
                                      bottomLeft.X,
                                      bottomLeft.Y));
        }
        private static BitMatrix sampleGrid(BitMatrix matrix,
                                            ResultPoint topLeft,
                                            ResultPoint bottomLeft,
                                            ResultPoint topRight,
                                            ResultPoint bottomRight,
                                            int xdimension,
                                            int ydimension)
        {
            // Note that unlike the QR Code sampler, we didn't find the center of modules, but the
            // very corners. So there is no 0.5f here; 0.0f is right.
            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(
                       matrix,
                       xdimension, ydimension,
                       0.0f,           // p1ToX
                       0.0f,           // p1ToY
                       xdimension,     // p2ToX
                       0.0f,           // p2ToY
                       xdimension,     // p3ToX
                       ydimension,     // p3ToY
                       0.0f,           // p4ToX
                       ydimension,     // p4ToY
                       topLeft.X,      // p1FromX
                       topLeft.Y,      // p1FromY
                       topRight.X,     // p2FromX
                       topRight.Y,     // p2FromY
                       bottomRight.X,  // p3FromX
                       bottomRight.Y,  // p3FromY
                       bottomLeft.X,   // p4FromX
                       bottomLeft.Y)); // p4FromY
        }
Esempio n. 3
0
 /// <summary> Sets the implementation of <see cref="GridSampler"/> used by the library. One global
 /// instance is stored, which may sound problematic. But, the implementation provided
 /// ought to be appropriate for the entire platform, and all uses of this library
 /// in the whole lifetime of the JVM. For instance, an Android activity can swap in
 /// an implementation that takes advantage of native platform libraries.
 /// </summary>
 /// <param name="newGridSampler">The platform-specific object to install.</param>
 public static void setGridSampler(GridSampler newGridSampler)
 {
     if (newGridSampler == null)
     {
         throw new System.ArgumentException();
     }
     gridSampler = newGridSampler;
 }
Esempio n. 4
0
 /// <summary> Sets the implementation of <see cref="GridSampler"/> used by the library. One global
 /// instance is stored, which may sound problematic. But, the implementation provided
 /// ought to be appropriate for the entire platform, and all uses of this library
 /// in the whole lifetime of the JVM. For instance, an Android activity can swap in
 /// an implementation that takes advantage of native platform libraries.
 /// </summary>
 /// <param name="newGridSampler">The platform-specific object to install.</param>
 public static void setGridSampler(GridSampler newGridSampler)
 {
     if (newGridSampler == null)
     {
         throw new System.ArgumentException();
     }
     gridSampler = newGridSampler;
 }
Esempio n. 5
0
        private static BitMatrix sampleGrid(MonochromeBitmapSource image,
                                            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.getX();
                bottomRightY       = alignmentPattern.getY();
                sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f;
            }
            else
            {
                // Don't have an alignment pattern, just make up the bottom-right point
                bottomRightX       = (topRight.getX() - topLeft.getX()) + bottomLeft.getX();
                bottomRightY       = (topRight.getY() - topLeft.getY()) + bottomLeft.getY();
                sourceBottomRightX = sourceBottomRightY = dimMinusThree;
            }

            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(
                       image,
                       dimension,
                       3.5f,
                       3.5f,
                       dimMinusThree,
                       3.5f,
                       sourceBottomRightX,
                       sourceBottomRightY,
                       3.5f,
                       dimMinusThree,
                       topLeft.getX(),
                       topLeft.getY(),
                       topRight.getX(),
                       topRight.getY(),
                       bottomRightX,
                       bottomRightY,
                       bottomLeft.getX(),
                       bottomLeft.getY()));
        }
Esempio n. 6
0
        /// <summary>
        /// Samples an Aztec matrix from an image
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="topLeft">The top left.</param>
        /// <param name="bottomLeft">The bottom left.</param>
        /// <param name="bottomRight">The bottom right.</param>
        /// <param name="topRight">The top right.</param>
        /// <returns></returns>
        private BitMatrix sampleGrid(BitMatrix image,
                                     ResultPoint topLeft,
                                     ResultPoint bottomLeft,
                                     ResultPoint bottomRight,
                                     ResultPoint topRight)
        {
            int dimension;

            if (compact)
            {
                dimension = 4 * nbLayers + 11;
            }
            else
            {
                if (nbLayers <= 4)
                {
                    dimension = 4 * nbLayers + 15;
                }
                else
                {
                    dimension = 4 * nbLayers + 2 * ((nbLayers - 4) / 8 + 1) + 15;
                }
            }

            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(image,
                                      dimension,
                                      dimension,
                                      0.5f,
                                      0.5f,
                                      dimension - 0.5f,
                                      0.5f,
                                      dimension - 0.5f,
                                      dimension - 0.5f,
                                      0.5f,
                                      dimension - 0.5f,
                                      topLeft.X,
                                      topLeft.Y,
                                      topRight.X,
                                      topRight.Y,
                                      bottomRight.X,
                                      bottomRight.Y,
                                      bottomLeft.X,
                                      bottomLeft.Y));
        }
Esempio n. 7
0
        private static BitMatrix sampleGrid(MonochromeBitmapSource image,
                                            ResultPoint topLeft,
                                            ResultPoint bottomLeft,
                                            ResultPoint bottomRight,
                                            int dimension)
        {
            // We make up the top right point for now, based on the others.
            // TODO: we actually found a fourth corner above and figured out which of two modules
            // it was the corner of. We could use that here and adjust for perspective distortion.
            float topRightX = (bottomRight.getX() - bottomLeft.getX()) + topLeft.getX();
            float topRightY = (bottomRight.getY() - bottomLeft.getY()) + topLeft.getY();

            // Note that unlike in the QR Code sampler, we didn't find the center of modules, but the
            // very corners. So there is no 0.5f here; 0.0f is right.
            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(
                       image,
                       dimension,
                       0.0f,
                       0.0f,
                       dimension,
                       0.0f,
                       dimension,
                       dimension,
                       0.0f,
                       dimension,
                       topLeft.getX(),
                       topLeft.getY(),
                       topRightX,
                       topRightY,
                       bottomRight.getX(),
                       bottomRight.getY(),
                       bottomLeft.getX(),
                       bottomLeft.getY()));
        }
Esempio n. 8
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="topLeft">The top left.</param>
        /// <param name="bottomLeft">The bottom left.</param>
        /// <param name="bottomRight">The bottom right.</param>
        /// <param name="topRight">The top right.</param>
        /// <returns></returns>
        private BitMatrix sampleGrid(BitMatrix image,
                                     ResultPoint topLeft,
                                     ResultPoint topRight,
                                     ResultPoint bottomRight,
                                     ResultPoint bottomLeft)
        {
            GridSampler sampler   = GridSampler.Instance;
            int         dimension = getDimension();

            float low  = dimension / 2.0f - nbCenterLayers;
            float high = dimension / 2.0f + nbCenterLayers;

            return(sampler.sampleGrid(image,
                                      dimension,
                                      dimension,
                                      low, low,   // topleft
                                      high, low,  // topright
                                      high, high, // bottomright
                                      low, high,  // bottomleft
                                      topLeft.X, topLeft.Y,
                                      topRight.X, topRight.Y,
                                      bottomRight.X, bottomRight.Y,
                                      bottomLeft.X, bottomLeft.Y));
        }
Esempio n. 9
0
        private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension)
        {
            GridSampler sampler = GridSampler.Instance;

            return(sampler.sampleGrid(image, dimension, dimension, transform));
        }
Esempio n. 10
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);
            }
            if (!ComputeDimension(topLeft, topRight, bottomLeft, moduleSize, out int dimension))
            {
                return(null);
            }
            Version provisionalVersion = 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 = GridSampler.SampleGrid(image, dimension, dimension, transform);

            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));
        }