public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image                = image;
     this.possibleCenters      = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback  = resultPointCallback;
 }
示例#2
0
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image                = image;
     this.possibleCenters      = new List <object>();
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback  = resultPointCallback;
 }
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     this.possibleCenters = new System.Collections.Generic.List<Object>(10);
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback = resultPointCallback;
 }
        public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image.BlackMatrix);
                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                throw new System.NotImplementedException("Detector(image.BlackMatrix).detect(hints) Not Implemented...");

                //DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(hints);
                //decoderResult = decoder.decode(detectorResult.Bits);
                //points = detectorResult.Points;
            }

            Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.MICRO_QR_CODE);

            if (decoderResult.ByteSegments != null)
            {
                result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
            }
            if (decoderResult.ECLevel != null)
            {
                result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
            }
            return(result);
        }
示例#5
0
        public virtual Result decode(BinaryBitmap image, Dictionary <object, object> hints)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image.BlackMatrix);
                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(hints);
                decoderResult = decoder.decode(detectorResult.Bits);
                points        = detectorResult.Points;
            }

            Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE);

            if (decoderResult.ByteSegments != null)
            {
                result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
            }
            if (decoderResult.ECLevel != null)
            {
                result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
            }
            return(result);
        }
示例#6
0
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image                = image;
     this.possibleCenters      = new System.Collections.Generic.List <Object>(10);
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback  = resultPointCallback;
 }
示例#7
0
        public Result decode(BinaryBitmap image, System.Collections.Hashtable hints)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image);
                if (bits.IsBlank())
                {
                    return(null);
                }

                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                DetectorResult detectorResult = new Detector(image).detect();
                if (detectorResult.IsBlank())
                {
                    return(null);
                }

                decoderResult = decoder.decode(detectorResult.Bits);
                if (decoderResult.IsBlank())
                {
                    return(null);
                }

                points = detectorResult.Points;
            }
            return(new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF417));
        }
示例#8
0
        /// <summary> <p>Decodes a PDF417 Code represented as a {@link BitMatrix}.
        /// A 1 or "true" is taken to mean a black module.</p>
        ///
        /// </summary>
        /// <param name="bits">booleans representing white/black PDF417 Code modules
        /// </param>
        /// <returns> text and bytes encoded within the PDF417 Code
        /// </returns>
        /// <throws>  ReaderException if the PDF417 Code cannot be decoded </throws>
        public DecoderResult decode(BitMatrix bits)
        {
            // Construct a parser to read the data codewords and error-correction level
            BitMatrixParser parser = new BitMatrixParser(bits);

            int[] codewords = parser.readCodewords();
            if (codewords == null || codewords.Length == 0)
            {
                return(null);
            }

            int ecLevel        = parser.ECLevel;
            int numECCodewords = 1 << (ecLevel + 1);

            int[] erasures = parser.Erasures;

            int?ceResult = correctErrors(codewords, erasures, numECCodewords);

            if (ceResult.IsBlank())
            {
                return(null);
            }

            bool success = verifyCodewordCount(codewords, numECCodewords);

            if (!success)
            {
                return(null);
            }

            // Decode the codewords
            return(DecodedBitStreamParser.decode(codewords));
        }
        // public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
        public Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image.BlackMatrix);
                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                DetectorResult detectorResult = new Detector(image.BlackMatrix).detect();
                decoderResult = decoder.decode(detectorResult.Bits);
                points        = detectorResult.Points;
            }
            Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.DATAMATRIX);

            if (decoderResult.ByteSegments != null)
            {
                result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments);
            }
            if (decoderResult.ECLevel != null)
            {
                result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString());
            }
            return(result);
        }
示例#10
0
        /// <summary>
        /// <p>Creates the version object based on the dimension of the original bit matrix from
        /// the datamatrix code.</p>
        ///
        /// <p>See ISO 16022:2006 Table 7 - ECC 200 symbol attributes</p>
        /// </summary>
        /// <param name="bitMatrix"> Original <seealso cref="BitMatrix"/> including alignment patterns </param>
        /// <returns> <seealso cref="Version"/> encapsulating the Data Matrix Code's "version" </returns>
        /// <exception cref="FormatException"> if the dimensions of the mapping matrix are not valid
        /// Data Matrix dimensions. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static Version readVersion(com.google.zxing.common.BitMatrix bitMatrix) throws com.google.zxing.FormatException
        private static Version readVersion(BitMatrix bitMatrix)
        {
            int numRows    = bitMatrix.Height;
            int numColumns = bitMatrix.Width;

            return(Version.getVersionForDimensions(numRows, numColumns));
        }
示例#11
0
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     this.possibleCenters = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback = resultPointCallback;
 }
示例#12
0
文件: Detector.cs 项目: whuacn/CJia
        private static BitMatrix sampleGrid(BitMatrix matrix, ResultPoint topLeft, ResultPoint bottomLeft, ResultPoint topRight, ResultPoint bottomRight, int dimension)
        {
            // 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, dimension, 0.0f, 0.0f, dimension, 0.0f, dimension, dimension, 0.0f, dimension, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRight.X, bottomRight.Y, bottomLeft.X, bottomLeft.Y));            // p4FromY
        }
示例#13
0
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     // this.possibleCenters = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com)
     this.possibleCenters      = new System.Collections.Generic.List <Object>(10); // added by .net follower (http://dotnetfollower.com)
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback  = resultPointCallback;
 }
		/// <param name="bitMatrix">{@link BitMatrix} to parse
		/// </param>
		/// <throws>  ReaderException if dimension is not >= 21 and 1 mod 4 </throws>
		internal BitMatrixParser(BitMatrix bitMatrix)
		{
			int dimension = bitMatrix.Dimension;
			if (dimension < 21 || (dimension & 0x03) != 1)
			{
				throw ReaderException.Instance;
			}
			this.bitMatrix = bitMatrix;
		}
示例#15
0
 public BinaryBitmap(Binarizer binarizer)
 {
     if (binarizer == null)
     {
         throw new Exception("Binarizer must be non-null.");
     }
     this.binarizer = binarizer;
     matrix = null;
 }
示例#16
0
 /// <param name="bitMatrix">{@link BitMatrix} to parse
 /// </param>
 /// <throws>  ReaderException if dimension is not >= 21 and 1 mod 4 </throws>
 internal BitMatrixParser(BitMatrix bitMatrix)
 {
     int dimension = bitMatrix.Dimension;
     if (dimension < 21 || (dimension & 0x03) != 1)
     {
         throw new Exception("ReaderException");
     }
     this.bitMatrix = bitMatrix;
 }
 /// <param name="bitMatrix"> <seealso cref="BitMatrix"/> to parse </param>
 /// <exception cref="FormatException"> if dimension is not >= 21 and 1 mod 4 </exception>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: BitMatrixParser(com.google.zxing.common.BitMatrix bitMatrix) throws com.google.zxing.FormatException
 internal BitMatrixParser(BitMatrix bitMatrix)
 {
     int dimension = bitMatrix.Height;
     if (dimension < 21 || (dimension & 0x03) != 1)
     {
       throw FormatException.FormatInstance;
     }
     this.bitMatrix = bitMatrix;
 }
示例#18
0
 public BinaryBitmap(Binarizer binarizer)
 {
     if (binarizer == null)
     {
         throw new System.ArgumentException("Binarizer must be non-null.");
     }
     this.binarizer = binarizer;
     matrix         = null;
 }
示例#19
0
        /// <param name="bitMatrix"> <seealso cref="BitMatrix"/> to parse </param>
        /// <exception cref="FormatException"> if dimension is not >= 21 and 1 mod 4 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: BitMatrixParser(com.google.zxing.common.BitMatrix bitMatrix) throws com.google.zxing.FormatException
        internal BitMatrixParser(BitMatrix bitMatrix)
        {
            int dimension = bitMatrix.Height;

            if (dimension < 21 || (dimension & 0x03) != 1)
            {
                throw FormatException.FormatInstance;
            }
            this.bitMatrix = bitMatrix;
        }
        /// <param name="bitMatrix">{@link BitMatrix} to parse
        /// </param>
        /// <throws>  ReaderException if dimension is not >= 11 and 1 mod 2 </throws>
        internal BitMatrixParser(BitMatrix bitMatrix)
        {
            int dimension = bitMatrix.Dimension;

            if (dimension < 11 || (dimension & 0x01) != 1)
            {
                throw ReaderException.Instance;
            }
            this.bitMatrix = bitMatrix;
        }
 /// <summary> <p>Creates a finder that will look in a portion of the whole image.</p>
 ///
 /// </summary>
 /// <param name="image">image to search
 /// </param>
 /// <param name="startX">left column from which to start searching
 /// </param>
 /// <param name="startY">top row from which to start searching
 /// </param>
 /// <param name="width">width of region to search
 /// </param>
 /// <param name="height">height of region to search
 /// </param>
 /// <param name="moduleSize">estimated module size so far
 /// </param>
 internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
 {
     this.image                = image;
     this.possibleCenters      = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(5));
     this.startX               = startX;
     this.startY               = startY;
     this.width                = width;
     this.height               = height;
     this.moduleSize           = moduleSize;
     this.crossCheckStateCount = new int[3];
     this.resultPointCallback  = resultPointCallback;
 }
示例#22
0
 /// <summary> <p>Creates a finder that will look in a portion of the whole image.</p>
 ///
 /// </summary>
 /// <param name="image">image to search
 /// </param>
 /// <param name="startX">left column from which to start searching
 /// </param>
 /// <param name="startY">top row from which to start searching
 /// </param>
 /// <param name="width">width of region to search
 /// </param>
 /// <param name="height">height of region to search
 /// </param>
 /// <param name="moduleSize">estimated module size so far
 /// </param>
 internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
 {
     this.image                = image;
     this.possibleCenters      = new List <object>();
     this.startX               = startX;
     this.startY               = startY;
     this.width                = width;
     this.height               = height;
     this.moduleSize           = moduleSize;
     this.crossCheckStateCount = new int[3];
     this.resultPointCallback  = resultPointCallback;
 }
		/// <summary> <p>Creates a finder that will look in a portion of the whole image.</p>
		/// 
		/// </summary>
		/// <param name="image">image to search
		/// </param>
		/// <param name="startX">left column from which to start searching
		/// </param>
		/// <param name="startY">top row from which to start searching
		/// </param>
		/// <param name="width">width of region to search
		/// </param>
		/// <param name="height">height of region to search
		/// </param>
		/// <param name="moduleSize">estimated module size so far
		/// </param>
		internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
		{
			this.image = image;
			this.possibleCenters = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(5));
			this.startX = startX;
			this.startY = startY;
			this.width = width;
			this.height = height;
			this.moduleSize = moduleSize;
			this.crossCheckStateCount = new int[3];
			this.resultPointCallback = resultPointCallback;
		}
        /// <param name="bitMatrix"> <seealso cref="BitMatrix"/> to parse </param>
        /// <exception cref="FormatException"> if dimension is < 8 or > 144 or not 0 mod 2 </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: BitMatrixParser(com.google.zxing.common.BitMatrix bitMatrix) throws com.google.zxing.FormatException
        internal BitMatrixParser(BitMatrix bitMatrix)
        {
            int dimension = bitMatrix.Height;
            if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0)
            {
              throw FormatException.FormatInstance;
            }

            version = readVersion(bitMatrix);
            this.mappingBitMatrix = extractDataRegion(bitMatrix);
            this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.Width, this.mappingBitMatrix.Height);
        }
 /// <summary>
 /// <p>Creates a finder that will look in a portion of the whole image.</p>
 /// </summary>
 /// <param name="image"> image to search </param>
 /// <param name="startX"> left column from which to start searching </param>
 /// <param name="startY"> top row from which to start searching </param>
 /// <param name="width"> width of region to search </param>
 /// <param name="height"> height of region to search </param>
 /// <param name="moduleSize"> estimated module size so far </param>
 internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     this.possibleCenters = new List<AlignmentPattern>(5);
     this.startX = startX;
     this.startY = startY;
     this.width = width;
     this.height = height;
     this.moduleSize = moduleSize;
     this.crossCheckStateCount = new int[3];
     this.resultPointCallback = resultPointCallback;
 }
示例#26
0
        /// <param name="bitMatrix">{@link BitMatrix} to parse
        /// </param>
        /// <throws>  ReaderException if dimension is < 10 or > 144 or not 0 mod 2 </throws>
        internal BitMatrixParser(BitMatrix bitMatrix)
        {
            int dimension = bitMatrix.Dimension;
            if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0)
            {
                throw new Exception("ReaderException");
            }

            version = readVersion(bitMatrix);
            this.mappingBitMatrix = extractDataRegion(bitMatrix);
            // TODO(bbrown): Make this work for rectangular symbols
            this.readMappingMatrix = BitMatrix.CreateSquareInstance(this.mappingBitMatrix.Dimension);
        }
示例#27
0
 /// <summary> <p>Creates a finder that will look in a portion of the whole image.</p>
 ///
 /// </summary>
 /// <param name="image">image to search
 /// </param>
 /// <param name="startX">left column from which to start searching
 /// </param>
 /// <param name="startY">top row from which to start searching
 /// </param>
 /// <param name="width">width of region to search
 /// </param>
 /// <param name="height">height of region to search
 /// </param>
 /// <param name="moduleSize">estimated module size so far
 /// </param>
 internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     // this.possibleCenters = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(5)); // commented by .net follower (http://dotnetfollower.com)
     this.possibleCenters      = new System.Collections.Generic.List <Object>(5); // added by .net follower (http://dotnetfollower.com)
     this.startX               = startX;
     this.startY               = startY;
     this.width                = width;
     this.height               = height;
     this.moduleSize           = moduleSize;
     this.crossCheckStateCount = new int[3];
     this.resultPointCallback  = resultPointCallback;
 }
示例#28
0
 /// <summary>
 /// <p>Implementations of this method reverse the data masking process applied to a QR Code and
 /// make its bits ready to read.</p>
 /// </summary>
 /// <param name="bits"> representation of QR Code bits </param>
 /// <param name="dimension"> dimension of QR Code, represented by bits, being unmasked </param>
 internal void unmaskBitMatrix(BitMatrix bits, int dimension)
 {
     for (int i = 0; i < dimension; i++)
     {
       for (int j = 0; j < dimension; j++)
       {
     if (isMasked(i, j))
     {
       bits.flip(j, i);
     }
       }
     }
 }
        /// <summary> <p>Creates the version object based on the dimension of the original bit matrix from
        /// the datamatrix code.</p>
        ///
        /// <p>See ISO 16022:2006 Table 7 - ECC 200 symbol attributes</p>
        ///
        /// </summary>
        /// <param name="bitMatrix">Original {@link BitMatrix} including alignment patterns
        /// </param>
        /// <returns> {@link Version} encapsulating the Data Matrix Code's "version"
        /// </returns>
        /// <throws>  ReaderException if the dimensions of the mapping matrix are not valid </throws>
        /// <summary> Data Matrix dimensions.
        /// </summary>
        internal Version readVersion(BitMatrix bitMatrix)
        {
            if (version != null)
            {
                return(version);
            }

            // TODO(bbrown): make this work for rectangular dimensions as well.
            int numRows    = bitMatrix.Dimension;
            int numColumns = numRows;

            return(Version.getVersionForDimensions(numRows, numColumns));
        }
示例#30
0
 /// <summary>
 /// <p>Implementations of this method reverse the data masking process applied to a QR Code and
 /// make its bits ready to read.</p>
 /// </summary>
 /// <param name="bits"> representation of QR Code bits </param>
 /// <param name="dimension"> dimension of QR Code, represented by bits, being unmasked </param>
 internal void unmaskBitMatrix(BitMatrix bits, int dimension)
 {
     for (int i = 0; i < dimension; i++)
     {
         for (int j = 0; j < dimension; j++)
         {
             if (isMasked(i, j))
             {
                 bits.flip(j, i);
             }
         }
     }
 }
示例#31
0
        /// <param name="bitMatrix"> <seealso cref="BitMatrix"/> to parse </param>
        /// <exception cref="FormatException"> if dimension is < 8 or > 144 or not 0 mod 2 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: BitMatrixParser(com.google.zxing.common.BitMatrix bitMatrix) throws com.google.zxing.FormatException
        internal BitMatrixParser(BitMatrix bitMatrix)
        {
            int dimension = bitMatrix.Height;

            if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0)
            {
                throw FormatException.FormatInstance;
            }

            version = readVersion(bitMatrix);
            this.mappingBitMatrix  = extractDataRegion(bitMatrix);
            this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.Width, this.mappingBitMatrix.Height);
        }
示例#32
0
        /// <summary> <p>Extracts the data region from a {@link BitMatrix} that contains
        /// alignment patterns.</p>
        ///
        /// </summary>
        /// <param name="bitMatrix">Original {@link BitMatrix} with alignment patterns
        /// </param>
        /// <returns> BitMatrix that has the alignment patterns removed
        /// </returns>
        internal BitMatrix extractDataRegion(BitMatrix bitMatrix)
        {
            if (version.IsBlank())
            {
                return(null);
            }
            int symbolSizeRows    = version.SymbolSizeRows;
            int symbolSizeColumns = version.SymbolSizeColumns;

            // TODO(bbrown): Make this work with rectangular codes
            if (bitMatrix.Dimension != symbolSizeRows)
            {
                throw new System.ArgumentException("Dimension of bitMarix must match the version size");
            }

            int dataRegionSizeRows    = version.DataRegionSizeRows;
            int dataRegionSizeColumns = version.DataRegionSizeColumns;

            int numDataRegionsRow    = symbolSizeRows / dataRegionSizeRows;
            int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;

            int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
            //int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;

            // TODO(bbrown): Make this work with rectangular codes
            BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionRow);

            for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow)
            {
                int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
                for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn)
                {
                    int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
                    for (int i = 0; i < dataRegionSizeRows; ++i)
                    {
                        int readRowOffset  = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
                        int writeRowOffset = dataRegionRowOffset + i;
                        for (int j = 0; j < dataRegionSizeColumns; ++j)
                        {
                            int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
                            if (bitMatrix.get_Renamed(readColumnOffset, readRowOffset))
                            {
                                int writeColumnOffset = dataRegionColumnOffset + j;
                                bitMatrixWithoutAlignment.set_Renamed(writeColumnOffset, writeRowOffset);
                            }
                        }
                    }
                }
            }
            return(bitMatrixWithoutAlignment);
        }
        /// <param name="bitMatrix">{@link BitMatrix} to parse
        /// </param>
        /// <throws>  ReaderException if dimension is < 10 or > 144 or not 0 mod 2 </throws>
        internal BitMatrixParser(BitMatrix bitMatrix)
        {
            int dimension = bitMatrix.Dimension;

            if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0)
            {
                throw ReaderException.Instance;
            }

            version = readVersion(bitMatrix);
            this.mappingBitMatrix = extractDataRegion(bitMatrix);
            // TODO(bbrown): Make this work for rectangular symbols
            this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.Dimension);
        }
		/// <summary> <p>Creates the version object based on the dimension of the original bit matrix from 
		/// the datamatrix code.</p>
		/// 
		/// <p>See ISO 16022:2006 Table 7 - ECC 200 symbol attributes</p>
		/// 
		/// </summary>
		/// <param name="bitMatrix">Original {@link BitMatrix} including alignment patterns
		/// </param>
		/// <returns> {@link Version} encapsulating the Data Matrix Code's "version"
		/// </returns>
		/// <throws>  ReaderException if the dimensions of the mapping matrix are not valid </throws>
		/// <summary> Data Matrix dimensions.
		/// </summary>
		internal Version readVersion(BitMatrix bitMatrix)
		{
			
			if (version != null)
			{
				return version;
			}
			
			// TODO(bbrown): make this work for rectangular dimensions as well.
			int numRows = bitMatrix.Dimension;
			int numColumns = numRows;
			
			return Version.getVersionForDimensions(numRows, numColumns);
		}
示例#35
0
        private static BitMatrix sampleGrid(BitMatrix 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.X - bottomLeft.X) + topLeft.X;
            float topRightY = (bottomRight.Y - bottomLeft.Y) + topLeft.Y;

            // 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.X, topLeft.Y, topRightX, topRightY, bottomRight.X, bottomRight.Y, bottomLeft.X, bottomLeft.Y));
        }
示例#36
0
        /// <summary> See ISO 18004:2006 Annex E</summary>
        internal BitMatrix buildFunctionPattern()
        {
            int       dimension = DimensionForVersion;
            BitMatrix bitMatrix = new BitMatrix(dimension);

            // Top left finder pattern + separator + format
            bitMatrix.setRegion(0, 0, 9, 9);

            // Vertical timing pattern
            bitMatrix.setRegion(9, 0, dimension - 9, 1);
            // Horizontal timing pattern
            bitMatrix.setRegion(0, 9, 1, dimension - 9);

            return(bitMatrix);
        }
示例#37
0
 /// <summary>
 /// <p>Convenience method that can decode a QR Code represented as a 2D array of booleans.
 /// "true" is taken to mean a black module.</p>
 /// </summary>
 /// <param name="image"> booleans representing white/black QR Code modules </param>
 /// <returns> text and bytes encoded within the QR Code </returns>
 /// <exception cref="FormatException"> if the QR Code cannot be decoded </exception>
 /// <exception cref="ChecksumException"> if error correction fails </exception>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public com.google.zxing.common.DecoderResult decode(boolean[][] image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.ChecksumException, com.google.zxing.FormatException
 public DecoderResult decode(bool[][] image, IDictionary<DecodeHintType, object> hints)
 {
     int dimension = image.Length;
     BitMatrix bits = new BitMatrix(dimension);
     for (int i = 0; i < dimension; i++)
     {
       for (int j = 0; j < dimension; j++)
       {
     if (image[i][j])
     {
       bits.set(j, i);
     }
       }
     }
     return decode(bits, hints);
 }
示例#38
0
 /// <summary> <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans.
 /// "true" is taken to mean a black module.</p>
 /// 
 /// </summary>
 /// <param name="image">booleans representing white/black Data Matrix Code modules
 /// </param>
 /// <returns> text and bytes encoded within the Data Matrix Code
 /// </returns>
 /// <throws>  ReaderException if the Data Matrix Code cannot be decoded </throws>
 public DecoderResult decode(bool[][] image)
 {
     int dimension = image.Length;
     BitMatrix bits = new BitMatrix(dimension);
     for (int i = 0; i < dimension; i++)
     {
         for (int j = 0; j < dimension; j++)
         {
             if (image[i][j])
             {
                 bits.set_Renamed(j, i);
             }
         }
     }
     return decode(bits);
 }
示例#39
0
文件: Detector.cs 项目: whuacn/CJia
        /// <param name="matrix">row of black/white values to search
        /// </param>
        /// <param name="column">x position to start search
        /// </param>
        /// <param name="row">y position to start search
        /// </param>
        /// <param name="width">the number of pixels to search on this row
        /// </param>
        /// <param name="pattern">pattern of counts of number of black and white pixels that are
        /// being searched for as a pattern
        /// </param>
        /// <returns> start/end horizontal offset of guard pattern, as an array of two ints.
        /// </returns>
        private static int[] findGuardPattern(BitMatrix matrix, int column, int row, int width, bool whiteFirst, int[] pattern)
        {
            int patternLength = pattern.Length;

            // TODO: Find a way to cache this array, as this method is called hundreds of times
            // per image, and we want to allocate as seldom as possible.
            int[] counters = new int[patternLength];
            bool  isWhite  = whiteFirst;

            int counterPosition = 0;
            int patternStart    = column;

            for (int x = column; x < column + width; x++)
            {
                bool pixel = matrix.get_Renamed(x, row);
                if (pixel ^ isWhite)
                {
                    counters[counterPosition]++;
                }
                else
                {
                    if (counterPosition == patternLength - 1)
                    {
                        if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE)
                        {
                            return(new int[] { patternStart, x });
                        }
                        patternStart += counters[0] + counters[1];
                        for (int y = 2; y < patternLength; y++)
                        {
                            counters[y - 2] = counters[y];
                        }
                        counters[patternLength - 2] = 0;
                        counters[patternLength - 1] = 0;
                        counterPosition--;
                    }
                    else
                    {
                        counterPosition++;
                    }
                    counters[counterPosition] = 1;
                    isWhite = !isWhite;
                }
            }
            return(null);
        }
示例#40
0
        /// <summary> <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans.
        /// "true" is taken to mean a black module.</p>
        ///
        /// </summary>
        /// <param name="image">booleans representing white/black Data Matrix Code modules
        /// </param>
        /// <returns> text and bytes encoded within the Data Matrix Code
        /// </returns>
        /// <throws>  ReaderException if the Data Matrix Code cannot be decoded </throws>
        public DecoderResult decode(bool[][] image)
        {
            int       dimension = image.Length;
            BitMatrix bits      = new BitMatrix(dimension);

            for (int i = 0; i < dimension; i++)
            {
                for (int j = 0; j < dimension; j++)
                {
                    if (image[i][j])
                    {
                        bits.set_Renamed(j, i);
                    }
                }
            }
            return(decode(bits));
        }
示例#41
0
        /// <summary> <p>Extracts the data region from a {@link BitMatrix} that contains
        /// alignment patterns.</p>
        /// 
        /// </summary>
        /// <param name="bitMatrix">Original {@link BitMatrix} with alignment patterns
        /// </param>
        /// <returns> BitMatrix that has the alignment patterns removed
        /// </returns>
        internal BitMatrix extractDataRegion(BitMatrix bitMatrix)
        {
            int symbolSizeRows = version.SymbolSizeRows;
            int symbolSizeColumns = version.SymbolSizeColumns;

            // TODO(bbrown): Make this work with rectangular codes
            if (bitMatrix.Dimension != symbolSizeRows)
            {
                throw new Exception("ArgumentException: Dimension of bitMarix must match the version size");
            }

            int dataRegionSizeRows = version.DataRegionSizeRows;
            int dataRegionSizeColumns = version.DataRegionSizeColumns;

            int numDataRegionsRow = Math.Floor(symbolSizeRows / dataRegionSizeRows);
            int numDataRegionsColumn = Math.Floor(symbolSizeColumns / dataRegionSizeColumns);

            int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
            //int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;

            // TODO(bbrown): Make this work with rectangular codes
            BitMatrix bitMatrixWithoutAlignment = BitMatrix.CreateSquareInstance(sizeDataRegionRow);
            for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow)
            {
                int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
                for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn)
                {
                    int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
                    for (int i = 0; i < dataRegionSizeRows; ++i)
                    {
                        int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
                        int writeRowOffset = dataRegionRowOffset + i;
                        for (int j = 0; j < dataRegionSizeColumns; ++j)
                        {
                            int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
                            if (bitMatrix.get_Renamed(readColumnOffset, readRowOffset))
                            {
                                int writeColumnOffset = dataRegionColumnOffset + j;
                                bitMatrixWithoutAlignment.set_Renamed(writeColumnOffset, writeRowOffset);
                            }
                        }
                    }
                }
            }
            return bitMatrixWithoutAlignment;
        }
示例#42
0
        /// <summary>
        /// <p>Extracts the data region from a <seealso cref="BitMatrix"/> that contains
        /// alignment patterns.</p>
        /// </summary>
        /// <param name="bitMatrix"> Original <seealso cref="BitMatrix"/> with alignment patterns </param>
        /// <returns> BitMatrix that has the alignment patterns removed </returns>
        internal BitMatrix extractDataRegion(BitMatrix bitMatrix)
        {
            int symbolSizeRows    = version.SymbolSizeRows;
            int symbolSizeColumns = version.SymbolSizeColumns;

            if (bitMatrix.Height != symbolSizeRows)
            {
                throw new System.ArgumentException("Dimension of bitMarix must match the version size");
            }

            int dataRegionSizeRows    = version.DataRegionSizeRows;
            int dataRegionSizeColumns = version.DataRegionSizeColumns;

            int numDataRegionsRow    = symbolSizeRows / dataRegionSizeRows;
            int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;

            int sizeDataRegionRow    = numDataRegionsRow * dataRegionSizeRows;
            int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;

            BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow);

            for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow)
            {
                int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
                for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn)
                {
                    int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
                    for (int i = 0; i < dataRegionSizeRows; ++i)
                    {
                        int readRowOffset  = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
                        int writeRowOffset = dataRegionRowOffset + i;
                        for (int j = 0; j < dataRegionSizeColumns; ++j)
                        {
                            int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
                            if (bitMatrix.get(readColumnOffset, readRowOffset))
                            {
                                int writeColumnOffset = dataRegionColumnOffset + j;
                                bitMatrixWithoutAlignment.set(writeColumnOffset, writeRowOffset);
                            }
                        }
                    }
                }
            }
            return(bitMatrixWithoutAlignment);
        }
示例#43
0
文件: Detector.cs 项目: whuacn/CJia
        /// <summary> <p>Detects a PDF417 Code in an image. Only checks 0 and 180 degree rotations.</p>
        ///
        /// </summary>
        /// <param name="hints">optional hints to detector
        /// </param>
        /// <returns> {@link DetectorResult} encapsulating results of detecting a PDF417 Code
        /// </returns>
        /// <throws>  ReaderException if no PDF417 Code can be found </throws>
        public DetectorResult detect(Dictionary <object, object> hints)
        {
            // Fetch the 1 bit matrix once up front.
            BitMatrix matrix = image.BlackMatrix;

            // Try to find the vertices assuming the image is upright.
            ResultPoint[] vertices = findVertices(matrix);
            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)
            {
                float moduleWidth = computeModuleWidth(vertices);
                if (moduleWidth < 1.0f)
                {
                    throw ReaderException.Instance;
                }

                int dimension = computeDimension(vertices[4], vertices[6], vertices[5], vertices[7], moduleWidth);
                if (dimension < 1)
                {
                    throw ReaderException.Instance;
                }

                // Deskew and sample image.
                BitMatrix bits = sampleGrid(matrix, vertices[4], vertices[5], vertices[6], vertices[7], dimension);
                return(new DetectorResult(bits, new ResultPoint[] { vertices[4], vertices[5], vertices[6], vertices[7] }));
            }
            else
            {
                throw ReaderException.Instance;
            }
        }
        /// <summary>
        /// <p>Extracts the data region from a <seealso cref="BitMatrix"/> that contains
        /// alignment patterns.</p>
        /// </summary>
        /// <param name="bitMatrix"> Original <seealso cref="BitMatrix"/> with alignment patterns </param>
        /// <returns> BitMatrix that has the alignment patterns removed </returns>
        internal BitMatrix extractDataRegion(BitMatrix bitMatrix)
        {
            int symbolSizeRows = version.SymbolSizeRows;
            int symbolSizeColumns = version.SymbolSizeColumns;

            if (bitMatrix.Height != symbolSizeRows)
            {
              throw new System.ArgumentException("Dimension of bitMarix must match the version size");
            }

            int dataRegionSizeRows = version.DataRegionSizeRows;
            int dataRegionSizeColumns = version.DataRegionSizeColumns;

            int numDataRegionsRow = symbolSizeRows / dataRegionSizeRows;
            int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;

            int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
            int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;

            BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow);
            for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow)
            {
              int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows;
              for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn)
              {
            int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns;
            for (int i = 0; i < dataRegionSizeRows; ++i)
            {
              int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
              int writeRowOffset = dataRegionRowOffset + i;
              for (int j = 0; j < dataRegionSizeColumns; ++j)
              {
                int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
                if (bitMatrix.get(readColumnOffset, readRowOffset))
                {
                  int writeColumnOffset = dataRegionColumnOffset + j;
                  bitMatrixWithoutAlignment.set(writeColumnOffset, writeRowOffset);
                }
              }
            }
              }
            }
            return bitMatrixWithoutAlignment;
        }
示例#45
0
        /// <summary> See ISO 18004:2006 Annex E</summary>
        internal BitMatrix buildFunctionPattern()
        {
            int       dimension = DimensionForVersion;
            BitMatrix bitMatrix = new BitMatrix(dimension);

            // Top left finder pattern + separator + format
            bitMatrix.setRegion(0, 0, 9, 9);
            // Top right finder pattern + separator + format
            bitMatrix.setRegion(dimension - 8, 0, 8, 9);
            // Bottom left finder pattern + separator + format
            bitMatrix.setRegion(0, dimension - 8, 9, 8);

            // Alignment patterns
            int max = alignmentPatternCenters.Length;

            for (int x = 0; x < max; x++)
            {
                int i = alignmentPatternCenters[x] - 2;
                for (int y = 0; y < max; y++)
                {
                    if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0))
                    {
                        // No alignment patterns near the three finder paterns
                        continue;
                    }
                    bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
                }
            }

            // Vertical timing pattern
            bitMatrix.setRegion(6, 9, 1, dimension - 17);
            // Horizontal timing pattern
            bitMatrix.setRegion(9, 6, dimension - 17, 1);

            if (versionNumber > 6)
            {
                // Version info, top right
                bitMatrix.setRegion(dimension - 11, 0, 3, 6);
                // Version info, bottom left
                bitMatrix.setRegion(0, dimension - 11, 6, 3);
            }

            return(bitMatrix);
        }
示例#46
0
        public Result decode(BinaryBitmap image, Dictionary <object, object> hints)
        {
            DecoderResult decoderResult;

            ResultPoint[] points;
            if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE))
            {
                BitMatrix bits = extractPureBits(image);
                decoderResult = decoder.decode(bits);
                points        = NO_POINTS;
            }
            else
            {
                DetectorResult detectorResult = new Detector(image).detect();
                decoderResult = decoder.decode(detectorResult.Bits);
                points        = detectorResult.Points;
            }
            return(new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.PDF417));
        }
示例#47
0
		/// <summary> <p>Decodes a PDF417 Code represented as a {@link BitMatrix}.
		/// A 1 or "true" is taken to mean a black module.</p>
		/// 
		/// </summary>
		/// <param name="bits">booleans representing white/black PDF417 Code modules
		/// </param>
		/// <returns> text and bytes encoded within the PDF417 Code
		/// </returns>
		/// <throws>  ReaderException if the PDF417 Code cannot be decoded </throws>
		public DecoderResult decode(BitMatrix bits)
		{
			// Construct a parser to read the data codewords and error-correction level
			BitMatrixParser parser = new BitMatrixParser(bits);
			int[] codewords = parser.readCodewords();
			if (codewords == null || codewords.Length == 0)
			{
				throw ReaderException.Instance;
			}
			
			int ecLevel = parser.ECLevel;
			int numECCodewords = 1 << (ecLevel + 1);
			int[] erasures = parser.Erasures;
			
			correctErrors(codewords, erasures, numECCodewords);
			verifyCodewordCount(codewords, numECCodewords);
			
			// Decode the codewords
			return DecodedBitStreamParser.decode(codewords);
		}
示例#48
0
文件: Decoder.cs 项目: slodge/Blooor
		/// <summary> <p>Decodes a QR Code represented as a {@link BitMatrix}. A 1 or "true" is taken to mean a black module.</p>
		/// 
		/// </summary>
		/// <param name="bits">booleans representing white/black QR Code modules
		/// </param>
		/// <returns> text and bytes encoded within the QR Code
		/// </returns>
		/// <throws>  ReaderException if the QR Code cannot be decoded </throws>
		public DecoderResult decode(BitMatrix bits)
		{
			
			// Construct a parser and read version, error-correction level
			BitMatrixParser parser = new BitMatrixParser(bits);
			Version version = parser.readVersion();
			ErrorCorrectionLevel ecLevel = parser.readFormatInformation().ErrorCorrectionLevel;
			
			// Read codewords
			sbyte[] codewords = parser.readCodewords();
			// Separate into data blocks
			DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel);
			
			// Count total number of data bytes
			int totalBytes = 0;
			for (int i = 0; i < dataBlocks.Length; i++)
			{
				totalBytes += dataBlocks[i].NumDataCodewords;
			}
			sbyte[] resultBytes = new sbyte[totalBytes];
			int resultOffset = 0;
			
			// Error-correct and copy data blocks together into a stream of bytes
			for (int j = 0; j < dataBlocks.Length; j++)
			{
				DataBlock dataBlock = dataBlocks[j];
				sbyte[] codewordBytes = dataBlock.Codewords;
				int numDataCodewords = dataBlock.NumDataCodewords;
				correctErrors(codewordBytes, numDataCodewords);
				for (int i = 0; i < numDataCodewords; i++)
				{
					resultBytes[resultOffset++] = codewordBytes[i];
				}
			}
			
			// Decode the contents of that stream of bytes
			return DecodedBitStreamParser.decode(resultBytes, version, ecLevel);
		}
		private static BitMatrix sampleGrid(BitMatrix matrix, ResultPoint topLeft, ResultPoint bottomLeft, ResultPoint topRight, ResultPoint bottomRight, int dimension)
		{
			
			// 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, dimension, 0.0f, 0.0f, dimension, 0.0f, dimension, dimension, 0.0f, dimension, topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomRight.X, bottomRight.Y, bottomLeft.X, bottomLeft.Y); // p4FromY
		}
 public MultiDetector(BitMatrix image)
     : base(image)
 {
 }
		/// <param name="matrix">row of black/white values to search
		/// </param>
		/// <param name="column">x position to start search
		/// </param>
		/// <param name="row">y position to start search
		/// </param>
		/// <param name="width">the number of pixels to search on this row
		/// </param>
		/// <param name="pattern">pattern of counts of number of black and white pixels that are
		/// being searched for as a pattern
		/// </param>
		/// <returns> start/end horizontal offset of guard pattern, as an array of two ints.
		/// </returns>
		private static int[] findGuardPattern(BitMatrix matrix, int column, int row, int width, bool whiteFirst, int[] pattern)
		{
			int patternLength = pattern.Length;
			// TODO: Find a way to cache this array, as this method is called hundreds of times
			// per image, and we want to allocate as seldom as possible.
			int[] counters = new int[patternLength];
			bool isWhite = whiteFirst;
			
			int counterPosition = 0;
			int patternStart = column;
			for (int x = column; x < column + width; x++)
			{
				bool pixel = matrix.get_Renamed(x, row);
				if (pixel ^ isWhite)
				{
					counters[counterPosition]++;
				}
				else
				{
					if (counterPosition == patternLength - 1)
					{
						if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE)
						{
							return new int[]{patternStart, x};
						}
						patternStart += counters[0] + counters[1];
						for (int y = 2; y < patternLength; y++)
						{
							counters[y - 2] = counters[y];
						}
						counters[patternLength - 2] = 0;
						counters[patternLength - 1] = 0;
						counterPosition--;
					}
					else
					{
						counterPosition++;
					}
					counters[counterPosition] = 1;
					isWhite = !isWhite;
				}
			}
			return null;
		}
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     // this.possibleCenters = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com)
     this.possibleCenters = new System.Collections.Generic.List<Object>(10); // added by .net follower (http://dotnetfollower.com)
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback = resultPointCallback;
 }
示例#53
0
		/// <summary> This method detects a barcode in a "pure" image -- that is, pure monochrome image
		/// which contains only an unrotated, unskewed, image of a barcode, with some white border
		/// around it. This is a specialized method that works exceptionally fast in this special
		/// case.
		/// </summary>
		private static BitMatrix extractPureBits(BinaryBitmap image)
		{
			// Now need to determine module size in pixels
			BitMatrix matrix = image.BlackMatrix;
			int height = matrix.Height;
			int width = matrix.Width;
			int minDimension = System.Math.Min(height, width);
			
			// First, skip white border by tracking diagonally from the top left down and to the right:
			int borderWidth = 0;
			while (borderWidth < minDimension && !matrix.get_Renamed(borderWidth, borderWidth))
			{
				borderWidth++;
			}
			if (borderWidth == minDimension)
			{
				throw ReaderException.Instance;
			}
			
			// And then keep tracking across the top-left black module to determine module size
			int moduleEnd = borderWidth;
			while (moduleEnd < minDimension && matrix.get_Renamed(moduleEnd, moduleEnd))
			{
				moduleEnd++;
			}
			if (moduleEnd == minDimension)
			{
				throw ReaderException.Instance;
			}
			
			int moduleSize = moduleEnd - borderWidth;
			
			// And now find where the rightmost black module on the first row ends
			int rowEndOfSymbol = width - 1;
			while (rowEndOfSymbol >= 0 && !matrix.get_Renamed(rowEndOfSymbol, borderWidth))
			{
				rowEndOfSymbol--;
			}
			if (rowEndOfSymbol < 0)
			{
				throw ReaderException.Instance;
			}
			rowEndOfSymbol++;
			
			// Make sure width of barcode is a multiple of module size
			if ((rowEndOfSymbol - borderWidth) % moduleSize != 0)
			{
				throw ReaderException.Instance;
			}
			int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;
			
			// Push in the "border" by half the module width so that we start
			// sampling in the middle of the module. Just in case the image is a
			// little off, this will help recover.
			borderWidth += (moduleSize >> 1);
			
			int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
			if (sampleDimension >= width || sampleDimension >= height)
			{
				throw ReaderException.Instance;
			}
			
			// Now just read off the bits
			BitMatrix bits = new BitMatrix(dimension);
			for (int y = 0; y < dimension; y++)
			{
				int iOffset = borderWidth + y * moduleSize;
				for (int x = 0; x < dimension; x++)
				{
					if (matrix.get_Renamed(borderWidth + x * moduleSize, iOffset))
					{
						bits.set_Renamed(x, y);
					}
				}
			}
			return bits;
		}
示例#54
0
        /// <summary> See ISO 18004:2006 Annex E</summary>
        internal BitMatrix buildFunctionPattern()
        {
            int dimension = DimensionForVersion;
            BitMatrix bitMatrix = new BitMatrix(dimension);

            // Top left finder pattern + separator + format
            bitMatrix.setRegion(0, 0, 9, 9);
            // Top right finder pattern + separator + format
            bitMatrix.setRegion(dimension - 8, 0, 8, 9);
            // Bottom left finder pattern + separator + format
            bitMatrix.setRegion(0, dimension - 8, 9, 8);

            // Alignment patterns
            int max = alignmentPatternCenters.Length;
            for (int x = 0; x < max; x++)
            {
                int i = alignmentPatternCenters[x] - 2;
                for (int y = 0; y < max; y++)
                {
                    if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0))
                    {
                        // No alignment patterns near the three finder paterns
                        continue;
                    }
                    bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
                }
            }

            // Vertical timing pattern
            bitMatrix.setRegion(6, 9, 1, dimension - 17);
            // Horizontal timing pattern
            bitMatrix.setRegion(9, 6, dimension - 17, 1);

            if (versionNumber > 6)
            {
                // Version info, top right
                bitMatrix.setRegion(dimension - 11, 0, 3, 6);
                // Version info, bottom left
                bitMatrix.setRegion(0, dimension - 11, 6, 3);
            }

            return bitMatrix;
        }
		/// <summary> <p>Creates a finder that will search the image for three finder patterns.</p>
		/// 
		/// </summary>
		/// <param name="image">image to search
		/// </param>
		public FinderPatternFinder(BitMatrix image):this(image, null)
		{
		}
示例#56
0
 public Detector(BitMatrix image)
 {
     this.image = image;
 }
示例#57
0
 private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension)
 {
     GridSampler sampler = GridSampler.Instance;
     return sampler.sampleGrid(image, dimension, transform);
 }
 /// <summary> <p>Creates a finder that will search the image for three finder patterns.</p>
 /// 
 /// </summary>
 /// <param name="image">image to search
 /// </param>
 //public FinderPatternFinder(BitMatrix image):this(image, null)
 //{
 //}
 public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback)
 {
     this.image = image;
     this.possibleCenters = new ArrayList();
     this.crossCheckStateCount = new int[5];
     this.resultPointCallback = resultPointCallback;
 }
		public MonochromeRectangleDetector(BitMatrix image)
		{
			this.image = image;
		}
		internal BitMatrixParser(BitMatrix bitMatrix)
		{
			this.bitMatrix = bitMatrix;
		}