Esempio n. 1
0
        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
            {
                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);
        }
Esempio n. 2
0
		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
			{
				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;
		}
Esempio n. 3
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);
				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);
		}
Esempio n. 4
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);
                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));
        }
		public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints)
		{
			System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
			DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints);
			for (int i = 0; i < detectorResult.Length; i++)
			{
				try
				{
					DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits);
					ResultPoint[] points = detectorResult[i].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());
					}
					results.Add(result);
				}
				catch (ReaderException)
				{
					// ignore and continue 
				}
			}
			if ((results.Count == 0))
			{
				return EMPTY_RESULT_ARRAY;
			}
			else
			{
				Result[] resultArray = new Result[results.Count];
				for (int i = 0; i < results.Count; i++)
				{
					resultArray[i] = (Result) results[i];
				}
				return resultArray;
			}
		}
Esempio n. 6
0
 public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints)
 {
     System.Collections.ArrayList results        = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
     DetectorResult[]             detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints);
     for (int i = 0; i < detectorResult.Length; i++)
     {
         try
         {
             DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits);
             ResultPoint[] points        = detectorResult[i].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());
             }
             results.Add(result);
         }
         catch (ReaderException)
         {
             // ignore and continue
         }
     }
     if ((results.Count == 0))
     {
         return(EMPTY_RESULT_ARRAY);
     }
     else
     {
         Result[] resultArray = new Result[results.Count];
         for (int i = 0; i < results.Count; i++)
         {
             resultArray[i] = (Result)results[i];
         }
         return(resultArray);
     }
 }
Esempio n. 7
0
		public Detector(BinaryBitmap image)
		{
			this.image = image;
		}
Esempio n. 8
0
 public Detector(BinaryBitmap image)
 {
     this.image = image;
 }
Esempio n. 9
0
 /// <summary> Locates and decodes a QR code in an image.
 ///
 /// </summary>
 /// <returns> a String representing the content encoded by the QR code
 /// </returns>
 /// <throws>  ReaderException if a QR code cannot be found, or cannot be decoded </throws>
 public virtual Result Decode(BinaryBitmap image)
 {
     return(Decode(image, null));
 }
Esempio n. 10
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;
		}
Esempio n. 11
0
		/// <summary> Locates and decodes a PDF417 code in an image.
		/// 
		/// </summary>
		/// <returns> a String representing the content encoded by the PDF417 code
		/// </returns>
		/// <throws>  ReaderException if a PDF417 code cannot be found, or cannot be decoded </throws>
		public Result Decode(BinaryBitmap image)
		{
			return Decode(image, null);
		}
		public Result[] decodeMultiple(BinaryBitmap image)
		{
			return decodeMultiple(image, null);
		}
Esempio n. 13
0
 public Result[] decodeMultiple(BinaryBitmap image)
 {
     return(decodeMultiple(image, null));
 }
Esempio n. 14
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);
        }