Exemple #1
0
        public FieldProperties(string name, ProcessingFieldType type, LogicalRectangle bounds, bool enableIcr, bool enableOcr, bool isNumerical, bool isICRSupported)
        {
            InitializeComponent();

            this.Text = "\"" + name + "\"" + " Properties";

            if (type == ProcessingFieldType.Text)
            {
                _methodGroup.Enabled  = true;
                _typeGroup.Enabled    = true;
                _enableOcr            = enableOcr;
                _chkEnableOcr.Checked = enableOcr;

                _enableIcr            = enableIcr;
                _chkEnableIcr.Checked = enableIcr && isICRSupported;

                _isNumerical = isNumerical;
                _radioTextNumerical.Checked = isNumerical;
                _radioTextCharacter.Checked = !isNumerical;
            }
            else
            {
                _methodGroup.Enabled = false;
                _typeGroup.Enabled   = false;

                _enableOcr            = true;
                _chkEnableOcr.Checked = true;

                _enableIcr            = false;
                _chkEnableIcr.Checked = false;

                _isNumerical = false;
                _radioTextNumerical.Checked = false;
                _radioTextCharacter.Checked = true;
            }

            _chkEnableIcr.Enabled = isICRSupported;

            _name         = name;
            _txtName.Text = name;

            _type         = type;
            _cmbType.Text = type.ToString();

            _left         = bounds.Left;
            _txtLeft.Text = bounds.Left.ToString();

            _top         = bounds.Top;
            _txtTop.Text = bounds.Top.ToString();

            _width         = bounds.Width;
            _txtWidth.Text = bounds.Width.ToString();

            _height         = bounds.Height;
            _txtHeight.Text = bounds.Height.ToString();
        }
 private IEnumerable<string> GetText(LogicalRectangle leadRect, BarcodeReadOptions[] coreReadOptions, ImageSource image, BarcodeImageType imageType)
 {
     var engine = new BarcodeEngine();
     engine.Reader.ImageType = imageType;
     var barcodeDatas = engine.Reader.ReadBarcodes(image.ToRasterImage(), leadRect, 10, BarcodeSymbologies.ToArray(), coreReadOptions);
     var textForStrategy = barcodeDatas
         .Select(data => data.Value)
         .DefaultIfEmpty();
     return textForStrategy;
 }
Exemple #3
0
        private IEnumerable <string> GetText(LogicalRectangle leadRect, BarcodeReadOptions[] coreReadOptions, IImage image, BarcodeImageType imageType)
        {
            var engine = new BarcodeEngine();

            engine.Reader.ImageType = imageType;
            var barcodeDatas    = engine.Reader.ReadBarcodes(image.FromImageToRasterImage(), leadRect, 10, BarcodeSymbologies.ToArray(), coreReadOptions);
            var textForStrategy = barcodeDatas
                                  .Select(data => data.Value)
                                  .DefaultIfEmpty();

            return(textForStrategy);
        }
        public IEnumerable<RecognitionResult> Recognize(BitmapSource bitmap, ZoneConfiguration config)
        {
            var coreReadOptions = CoreReadOptions;

            var leadRect = new LogicalRectangle(0, 0, bitmap.PixelWidth, bitmap.PixelHeight, LogicalUnit.Pixel);

            var unitsOfWork = from strategy in BarcodeStrategies
                                   let filteredImage = Freeze(strategy.BitmapFilter.Apply(bitmap))
                                   select new { ImageType = strategy.ImageType, FilteredImage = filteredImage };

            var selectMany = unitsOfWork.SelectMany(u => GetText(leadRect, coreReadOptions, u.FilteredImage, u.ImageType));
            return selectMany.Select(s => new RecognitionResult(s, 1));            
        }
Exemple #5
0
        public IEnumerable <RecognitionResult> Recognize(IImage bitmap, ZoneConfiguration config)
        {
            var coreReadOptions = CoreReadOptions;

            var leadRect = new LogicalRectangle(0, 0, bitmap.Width, bitmap.Height, LogicalUnit.Pixel);

            var unitsOfWork = from strategy in BarcodeStrategies
                              let filteredImage = strategy.BitmapFilter.Apply(bitmap)
                                                  select new { ImageType = strategy.ImageType, FilteredImage = filteredImage };

            var selectMany = unitsOfWork.SelectMany(u => GetText(leadRect, coreReadOptions, u.FilteredImage, u.ImageType));

            return(selectMany.Select(s => new RecognitionResult(s, 1)));
        }
Exemple #6
0
        private static string DetectAndRecognizeMicr(string fileName)
        {
            try
            {
                //Initialize the codecs class and load the image
                using (var codecs = new RasterCodecs())
                    using (var img = codecs.Load(fileName))
                    {
                        //prepare the MICR detector command and run it
                        var micrDetector = new MICRCodeDetectionCommand
                        {
                            SearchingZone = new LeadRect(0, 0, img.Width, img.Height)
                        };
                        micrDetector.Run(img);

                        //See if there is a MICR detected - if not return
                        if (micrDetector.MICRZone == LeadRect.Empty)
                        {
                            return("No MICR detected in this file.");
                        }

                        //if there is a MICR zone detected startup OCR
                        using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
                        {
                            ocrEngine.Startup(null, null, null, null);

                            //create the OCR Page
                            var ocrPage = ocrEngine.CreatePage(img, OcrImageSharingMode.None);

                            //Create the OCR zone for the MICR and add to the Ocr Page and recognize
                            var micrZone = new OcrZone
                            {
                                Bounds   = LogicalRectangle.FromRectangle(micrDetector.MICRZone),
                                ZoneType = OcrZoneType.Micr
                            };
                            ocrPage.Zones.Add(micrZone);
                            ocrPage.Recognize(null);

                            //return the MICR text
                            return(ocrPage.GetText(-1));
                        }
                    }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }