This class implements a local thresholding algorithm, which while slower than the GlobalHistogramBinarizer, is fairly efficient for what it does. It is designed for high frequency images of barcodes with black data on white backgrounds. For this application, it does a much better job than a global blackpoint with severe shadows and gradients. However it tends to produce artifacts on lower frequency images and is therefore not a good general purpose binarizer for uses outside ZXing. This class extends GlobalHistogramBinarizer, using the older histogram approach for 1D readers, and the newer local approach for 2D readers. 1D decoding using a per-row histogram is already inherently local, and only fails for horizontal gradients. We can revisit that problem later, but for now it was not a win to use local blocks for 1D. This Binarizer is the default for the unit tests and the recommended class for library users.
Inheritance: GlobalHistogramBinarizer
Example #1
0
        /// <summary>
        /// To scan the Image and return the Barcode Data on it
        /// </summary>
        /// <returns>String</returns>
        public string getBarcodeData()
        {
            string barcode;
            
            WriteableBitmap wbmp = new WriteableBitmap(ImageSource);

            RGBLuminanceSource lum = new RGBLuminanceSource(wbmp, wbmp.PixelWidth, wbmp.PixelHeight);
            HybridBinarizer binarizer = new HybridBinarizer(lum);
            BinaryBitmap binBmp = new BinaryBitmap(binarizer);

            try
            {
                Result res = OneDreader.decode(binBmp);
                barcode = res.Text;
                return barcode;
            }
            catch { }
            try
            {
                Result res = QRreader.decode(binBmp);
                barcode = res.Text;
                return barcode;
            }
            catch { }

            try
            {
                Result res = Matreader.decode(binBmp);
                barcode = res.Text;
                return barcode;
            }
            catch { }
            try
            {
                Result res = pdfReader.decode(binBmp);
                barcode = res.Text;
                return barcode;
            }
            catch { }

            return barcode = "No Barcode Found"; //If no matching found
        }
Example #2
0
        /// <summary>
        /// To scan the Image and return the Barcode format on it.
        /// </summary>
        /// <returns>String</returns>
        public string getBarcodeFormat()
        {
            string format;
            WriteableBitmap wbmp = new WriteableBitmap(ImageSource);

            RGBLuminanceSource lum = new RGBLuminanceSource(wbmp, wbmp.PixelWidth, wbmp.PixelHeight);
            HybridBinarizer binarizer = new HybridBinarizer(lum);
            BinaryBitmap binBmp = new BinaryBitmap(binarizer);

            try
            {
                Result res = OneDreader.decode(binBmp);
                format = res.BarcodeFormat.ToString();
                return format;
            }
            catch { }
            try
            {
                Result res = QRreader.decode(binBmp);
                format = res.BarcodeFormat.ToString();
                return format;
            }
            catch { }

            try
            {
                Result res = Matreader.decode(binBmp);
                format = res.BarcodeFormat.ToString();
                return format;
            }
            catch { }
            try
            {
                Result res = pdfReader.decode(binBmp);
                format = res.BarcodeFormat.ToString();
                return format;
            }
            catch { }

            return format = "No Format"; //If no matching found
        }