Beispiel #1
0
        private void _cmbOcrModules_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (WaitCursor wait = new WaitCursor())
            {
                if (_cmbOcrModules.SelectedIndex < 0)
                {
                    return;
                }

                if (_ocrPage != null)
                {
                    _ocrPage.Dispose();
                    _ocrPage = null;
                }

                // Load the default image associated with each ocr module.
                LoadOcrModuleAssociatedImage();

                // Save the image file name the user associate with the selected OCR module.
                MyItemData itemData = (MyItemData)_cmbOcrModules.Items[_cmbOcrModules.SelectedIndex];
                itemData.ImageFileName = _lblImageFileName.Text;
                this._cmbOcrModules.SelectedIndexChanged          -= new System.EventHandler(this._cmbOcrModules_SelectedIndexChanged);
                _cmbOcrModules.Items[_cmbOcrModules.SelectedIndex] = itemData;
                this._cmbOcrModules.SelectedIndexChanged          += new System.EventHandler(this._cmbOcrModules_SelectedIndexChanged);
                _omrOptionsButton.Enabled = ((OcrZoneType)itemData.ZoneType == OcrZoneType.Omr);

                UpdateMyControls();
            }
        }
Beispiel #2
0
        void LoadOcrModuleAssociatedImage()
        {
            MyItemData itemData = (MyItemData)_cmbOcrModules.Items[_cmbOcrModules.SelectedIndex];

            LoadImage(itemData.ImageFileName);
            _lblImageFileName.Text = itemData.ImageFileName;
        }
Beispiel #3
0
        private void _btnBrowseImageFile_Click(object sender, EventArgs e)
        {
            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;
            try
            {
                if (loader.Load(this, _codecs, false) > 0)
                {
                    if (LoadImage(loader.FileName))
                    {
                        _openInitialPath       = Path.GetDirectoryName(loader.FileName);
                        _lblImageFileName.Text = loader.FileName;
                        MyItemData itemData = (MyItemData)_cmbOcrModules.Items[_cmbOcrModules.SelectedIndex];
                        itemData.ImageFileName = loader.FileName;
                        this._cmbOcrModules.SelectedIndexChanged          -= new System.EventHandler(this._cmbOcrModules_SelectedIndexChanged);
                        _cmbOcrModules.Items[_cmbOcrModules.SelectedIndex] = itemData;
                        this._cmbOcrModules.SelectedIndexChanged          += new System.EventHandler(this._cmbOcrModules_SelectedIndexChanged);
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowFileOpenError(this, loader.FileName, ex);
            }
        }
Beispiel #4
0
        void AddZones(bool bUserDrawnZone)
        {
            try
            {
                if (bUserDrawnZone && (_frameRect.Width < 2 || _frameRect.Height < 2))
                {
                    return;
                }

                // Initialize the OcrZone and add it to the image.
                OcrZone     zoneData       = new OcrZone();
                MyItemData  itemData       = (MyItemData)_cmbOcrModules.SelectedItem;
                OcrZoneType selectedModule = (OcrZoneType)itemData.ZoneType;

                switch (selectedModule)
                {
                case OcrZoneType.Text: // AUTO
                    if (bUserDrawnZone)
                    {
                        zoneData.Bounds   = _frameRect;
                        zoneData.ZoneType = OcrZoneType.Text;
                        _ocrPage.Zones.Add(zoneData);
                    }
                    else
                    {
                        _ocrPage.AutoZone(null);
                    }
                    break;

                case OcrZoneType.Micr: // MICR
                    if (bUserDrawnZone)
                    {
                        zoneData.Bounds = _frameRect;
                    }
                    else
                    {
                        zoneData.Bounds = new LeadRect(38, 678, 1655, 87);
                    }

                    zoneData.ZoneType = OcrZoneType.Micr;
                    _ocrPage.Zones.Add(zoneData);
                    break;

                case OcrZoneType.Omr: // OMR
                    if (bUserDrawnZone)
                    {
                        zoneData.Bounds   = _frameRect;
                        zoneData.ZoneType = OcrZoneType.Omr;
                        _ocrPage.Zones.Add(zoneData);
                    }
                    else
                    {
                        _ocrPage.LoadZones(Path.Combine(ImagesFolder, "Mix_omr.ozf"));
                    }
                    break;

                case OcrZoneType.Icr: // HandPrintedCharacter
                    if (bUserDrawnZone)
                    {
                        zoneData.Bounds = _frameRect;
                    }
                    else
                    {
                        zoneData.Bounds = new LeadRect(0, 0, _ocrPage.Width, _ocrPage.Height);
                    }

                    zoneData.ZoneType         = OcrZoneType.Icr;
                    zoneData.CharacterFilters = (OcrZoneCharacterFilters)itemData.CharacterFilters;
                    _ocrPage.Zones.Add(zoneData);
                    break;
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
        }
Beispiel #5
0
        void InitEngines()
        {
            _documentFormatSelector.SetDocumentWriter(_ocrEngine.DocumentWriterInstance, false);

            StartupEngine();

            _documentFormatSelector.SetOcrEngineType(_ocrEngineType);

            if (_ocrEngineType == OcrEngineType.OmniPageArabic)
            {
                _autoOcrImageName = "ArabicSample.Tif";
            }
            else
            {
                _autoOcrImageName = "OCR1.Tif";
            }

            // Add the selected engine name to the demo caption
            Text = Text + " [" + _ocrEngineType.ToString() + " Engine]";

            UpdateSupportedOcrModulesList();
            UpdateMyControls();
            Properties.Settings settings = new Properties.Settings();

            // If user provided a command line argument then forget about the saved OCR Module
            // otherwise use the saved OCR module (if there is any).
            if (Environment.GetCommandLineArgs().Length > 1)
            {
                String[] arguments = Environment.GetCommandLineArgs();
                if (arguments[1].Equals("Auto"))
                {
                    _cmbOcrModules.SelectedIndex = 1;
                }
                else if (arguments[1].Equals("Omr"))
                {
                    _cmbOcrModules.SelectedIndex = 2;
                }
                else if (arguments[1].Equals("HnrText"))
                {
                    _cmbOcrModules.SelectedIndex = 3;
                }
                else if (arguments[1].Equals("HnrNum"))
                {
                    _cmbOcrModules.SelectedIndex = 4;
                }
                else
                {
                    _cmbOcrModules.SelectedIndex = 0;
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(settings.OCRModule))
                {
                    for (int i = 0; i < _cmbOcrModules.Items.Count; i++)
                    {
                        MyItemData itemData = (MyItemData)_cmbOcrModules.Items[i];
                        if (itemData.ZoneType == (int)Enum.Parse(typeof(OcrZoneType), settings.OCRModule))
                        {
                            _cmbOcrModules.SelectedIndex = i;
                            break;
                        }
                    }
                    if (_cmbOcrModules.SelectedIndex < 0) // No match found
                    {
                        _cmbOcrModules.SelectedIndex = 0;
                    }
                }
                else
                {
                    _cmbOcrModules.SelectedIndex = 0;
                }
            }

            if (_ocrEngine != null && _ocrEngine.IsStarted)
            {
                DocumentFormat format = DocumentFormat.Pdf;

                /* Load settings for the selected Document Format */
                if (!String.IsNullOrEmpty(settings.DocumentFormat))
                {
                    try
                    {
                        format = (DocumentFormat)Enum.Parse(typeof(DocumentFormat), settings.DocumentFormat);
                    }
                    catch
                    {
                    }
                }

                _documentFormatSelector.SelectedFormat = format;
            }

            /* Load settings for user selected View Final Document check box status */
            _cbViewFinalDocument.Checked = settings.ViewFinalDocument;
        }