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.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;
		}
        // 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public Result[] decodeMultiple(BinaryBitmap image, Dictionary <object, object> hints)
        {
            List <object> results = new List <object>();

            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);
            }
        }
 // public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
 public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com)
 {
     // System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // commented by .net follower (http://dotnetfollower.com)
     System.Collections.Generic.List <Object> results = new System.Collections.Generic.List <Object>(10); // added by .net follower (http://dotnetfollower.com)
     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 re)
         {
             // 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);
     }
 }
		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 re)
				{
					// 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;
			}
		}
Exemplo n.º 7
0
        // Note that we don't try rotation without the try harder flag, even if rotation was supported.
        public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints)
        {
            var retval = doDecode(image, hints);

            if (retval.HasValue())
            {
                return(retval);
            }
            else
            {
                bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER);
                if (tryHarder && image.RotateSupported)
                {
                    BinaryBitmap rotatedImage = image.rotateCounterClockwise();
                    Result       result       = doDecode(rotatedImage, hints);

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

                    // Record that we found it rotated 90 degrees CCW / 270 degrees CW
                    System.Collections.Hashtable metadata = result.ResultMetadata;
                    int orientation = 270;
                    if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION))
                    {
                        // But if we found it reversed in doDecode(), add in that result here:
                        orientation = (orientation + ((System.Int32)metadata[ResultMetadataType.ORIENTATION])) % 360;
                    }
                    result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object)orientation);
                    // Update result points
                    ResultPoint[] points = result.ResultPoints;
                    int           height = rotatedImage.Height;
                    for (int i = 0; i < points.Length; i++)
                    {
                        points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X);
                    }
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 8
0
 public Result[] decodeMultiple2(BinaryBitmap image, Dictionary<object, object> hints)
 {
     ArrayList results = new ArrayList();
     DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints);
     for (int i = 0; i < detectorResult.Length; i++)
     {
         try
         {
             DecoderResult decoderResult = Decoder.decode2(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 (Exception e)
         {
             if (e.Message.IndexOf("ReaderException") < 0)
                 throw e;
             // 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;
     }
 }
Exemplo n.º 9
0
 // Note that we don't try rotation without the try harder flag, even if rotation was supported.
 // public virtual Result decode(BinaryBitmap image, System.Collections.Hashtable hints) // commented by .net follower (http://dotnetfollower.com)
 public virtual Result decode(BinaryBitmap image, System.Collections.Generic.Dictionary <Object, Object> hints) // added by .net follower (http://dotnetfollower.com)
 {
     try
     {
         return(doDecode(image, hints));
     }
     catch (ReaderException re)
     {
         bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER);
         if (tryHarder && image.RotateSupported)
         {
             BinaryBitmap rotatedImage = image.rotateCounterClockwise();
             Result       result       = doDecode(rotatedImage, hints);
             // Record that we found it rotated 90 degrees CCW / 270 degrees CW
             // System.Collections.Hashtable metadata = result.ResultMetadata; // commented by .net follower (http://dotnetfollower.com)
             System.Collections.Generic.Dictionary <Object, Object> metadata = result.ResultMetadata; // added by .net follower (http://dotnetfollower.com)
             int orientation = 270;
             if (metadata != null && metadata.ContainsKey(ResultMetadataType.ORIENTATION))
             {
                 // But if we found it reversed in doDecode(), add in that result here:
                 orientation = (orientation + ((System.Int32)metadata[ResultMetadataType.ORIENTATION])) % 360;
             }
             result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object)orientation);
             // Update result points
             ResultPoint[] points = result.ResultPoints;
             int           height = rotatedImage.Height;
             for (int i = 0; i < points.Length; i++)
             {
                 points[i] = new ResultPoint(height - points[i].Y - 1, points[i].X);
             }
             return(result);
         }
         else
         {
             throw re;
         }
     }
 }
Exemplo n.º 10
0
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public com.google.zxing.Result[] decodeMultiple(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException
 public Result[] decodeMultiple(BinaryBitmap image, IDictionary<DecodeHintType, object> hints)
 {
     List<Result> results = new List<Result>();
     DetectorResult[] detectorResults = (new MultiDetector(image.BlackMatrix)).detectMulti(hints);
     foreach (DetectorResult detectorResult in detectorResults)
     {
       try
       {
     DecoderResult decoderResult = Decoder.decode(detectorResult.Bits, hints);
     ResultPoint[] points = detectorResult.Points;
     Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE);
     IList<sbyte[]> byteSegments = decoderResult.ByteSegments;
     if (byteSegments != null)
     {
       result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
     }
     string ecLevel = decoderResult.ECLevel;
     if (ecLevel != null)
     {
       result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
     }
     results.Add(result);
       }
       catch (ReaderException re)
       {
     // ignore and continue
       }
     }
     if (results.Count == 0)
     {
       return EMPTY_RESULT_ARRAY;
     }
     else
     {
       return results.ToArray();
     }
 }
Exemplo n.º 11
0
        /// <summary> We're going to examine rows from the middle outward, searching alternately above and below the
        /// middle, and farther out each time. rowStep is the number of rows between each successive
        /// attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then
        /// middle + rowStep, then middle - (2 * rowStep), etc.
        /// rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily
        /// decided that moving up and down by about 1/16 of the image is pretty good; we try more of the
        /// image if "trying harder".
        ///
        /// </summary>
        /// <param name="image">The image to decode
        /// </param>
        /// <param name="hints">Any hints that were requested
        /// </param>
        /// <returns> The contents of the decoded barcode
        /// </returns>
        /// <throws>  ReaderException Any spontaneous errors which occur </throws>
        private Result doDecode(BinaryBitmap image, Dictionary <object, object> hints)
        {
            int      width  = image.Width;
            int      height = image.Height;
            BitArray row    = new BitArray(width);

            int  middle    = height >> 1;
            bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER);
            int  rowStep   = System.Math.Max(1, height >> (tryHarder?7:4));
            int  maxLines;

            if (tryHarder)
            {
                maxLines = height;                 // Look at the whole image, not just the center
            }
            else
            {
                maxLines = 9;                 // Nine rows spaced 1/16 apart is roughly the middle half of the image
            }

            for (int x = 0; x < maxLines; x++)
            {
                // Scanning from the middle out. Determine which row we're looking at next:
                int  rowStepsAboveOrBelow = (x + 1) >> 1;
                bool isAbove   = (x & 0x01) == 0;               // i.e. is x even?
                int  rowNumber = middle + rowStep * (isAbove?rowStepsAboveOrBelow:-rowStepsAboveOrBelow);
                if (rowNumber < 0 || rowNumber >= height)
                {
                    // Oops, if we run off the top or bottom, stop
                    break;
                }

                // Estimate black point for this row and load it:
                try
                {
                    row = image.getBlackRow(rowNumber, row);
                }
                catch (ReaderException)
                {
                    continue;
                }

                // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to
                // handle decoding upside down barcodes.
                for (int attempt = 0; attempt < 2; attempt++)
                {
                    if (attempt == 1)
                    {
                        // trying again?
                        row.reverse();                         // reverse the row and continue
                        // This means we will only ever draw result points *once* in the life of this method
                        // since we want to avoid drawing the wrong points after flipping the row, and,
                        // don't want to clutter with noise from every single row scan -- just the scans
                        // that start on the center line.
                        if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
                        {
                            Dictionary <object, object>    newHints = new Dictionary <object, object>();
                            System.Collections.IEnumerator hintEnum = hints.Keys.GetEnumerator();
                            //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
                            while (hintEnum.MoveNext())
                            {
                                //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                                System.Object key = hintEnum.Current;
                                if (!key.Equals(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
                                {
                                    newHints[key] = hints[key];
                                }
                            }
                            hints = newHints;
                        }
                    }
                    try
                    {
                        // Look for a barcode
                        Result result = decodeRow(rowNumber, row, hints);
                        // We found our barcode
                        if (attempt == 1)
                        {
                            // But it was upside down, so note that
                            result.putMetadata(ResultMetadataType.ORIENTATION, (System.Object) 180);
                            // And remember to flip the result points horizontally.
                            ResultPoint[] points = result.ResultPoints;
                            points[0] = new ResultPoint(width - points[0].X - 1, points[0].Y);
                            points[1] = new ResultPoint(width - points[1].X - 1, points[1].Y);
                        }
                        return(result);
                    }
                    catch (ReaderException)
                    {
                        // continue -- just couldn't decode this row
                    }
                }
            }

            throw ReaderException.Instance;
        }
Exemplo n.º 12
0
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public com.google.zxing.Result decode(com.google.zxing.BinaryBitmap image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException
 public Result decode(BinaryBitmap image, IDictionary<DecodeHintType, 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();
       decoderResult = decoder.decode(detectorResult.Bits);
       points = detectorResult.Points;
     }
     Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.DATA_MATRIX);
     IList<sbyte[]> byteSegments = decoderResult.ByteSegments;
     if (byteSegments != null)
     {
       result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
     }
     string ecLevel = decoderResult.ECLevel;
     if (ecLevel != null)
     {
       result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
     }
     return result;
 }
Exemplo n.º 13
0
        /// <summary>
        /// <p>Like <seealso cref="#decodeRow(int, BitArray, java.util.Map)"/>, but
        /// allows caller to inform method about where the UPC/EAN start pattern is
        /// found. This allows this to be computed once and reused across many implementations.</p>
        /// </summary>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public com.google.zxing.Result decodeRow(int rowNumber, com.google.zxing.common.BitArray row, int[] startGuardRange, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException
        public virtual Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, IDictionary<DecodeHintType, object> hints)
        {
            //ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
            ResultPointCallback resultPointCallback = null;
            if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
            {
            resultPointCallback = (ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
            }

            if (resultPointCallback != null)
            {
              resultPointCallback.foundPossibleResultPoint(new ResultPoint((startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber));
            }

            StringBuilder result = decodeRowStringBuffer;
            result.Length = 0;
            int endStart = decodeMiddle(row, startGuardRange, result);

            if (resultPointCallback != null)
            {
              resultPointCallback.foundPossibleResultPoint(new ResultPoint(endStart, rowNumber));
            }

            int[] endRange = decodeEnd(row, endStart);

            if (resultPointCallback != null)
            {
              resultPointCallback.foundPossibleResultPoint(new ResultPoint((endRange[0] + endRange[1]) / 2.0f, rowNumber));
            }

            // Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
            // spec might want more whitespace, but in practice this is the maximum we can count on.
            int end = endRange[1];
            int quietEnd = end + (end - endRange[0]);
            if (quietEnd >= row.Size || !row.isRange(end, quietEnd, false))
            {
              throw NotFoundException.NotFoundInstance;
            }

            string resultString = result.ToString();
            if (!checkChecksum(resultString))
            {
              throw ChecksumException.ChecksumInstance;
            }

            float left = (float)(startGuardRange[1] + startGuardRange[0]) / 2.0f;
            float right = (float)(endRange[1] + endRange[0]) / 2.0f;
            BarcodeFormat format = BarcodeFormat;
            Result decodeResult = new Result(resultString, null, new ResultPoint[]{new ResultPoint(left, (float) rowNumber), new ResultPoint(right, (float) rowNumber)}, format); // no natural byte representation for these barcodes

            try
            {
              Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
              decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.Text);
              decodeResult.putAllMetadata(extensionResult.ResultMetadata);
              decodeResult.addResultPoints(extensionResult.ResultPoints);
            }
            catch (ReaderException re)
            {
              // continue
            }

            if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A)
            {
              string countryID = eanManSupport.lookupCountryIdentifier(resultString);
              if (countryID != null)
              {
            decodeResult.putMetadata(ResultMetadataType.POSSIBLE_COUNTRY, countryID);
              }
            }

            return decodeResult;
        }