Exemplo n.º 1
0
        public MasterForm LoadMasterForm(string attributesFileName, string fieldsFileName)
        {
            FormProcessingEngine tempProcessingEngine = new FormProcessingEngine();

            tempProcessingEngine.OcrEngine = OcrEngine;
            //tempProcessingEngine.BarcodeEngine = null;

            MasterForm form = new MasterForm();

            if (File.Exists(attributesFileName))
            {
                byte[] formData = File.ReadAllBytes(attributesFileName);
                form.Attributes.SetData(formData);
                form.Properties = RecognitionEngine.GetFormProperties(form.Attributes);
            }

            if (File.Exists(fieldsFileName))
            {
                tempProcessingEngine.LoadFields(fieldsFileName);
                form.Resolution      = tempProcessingEngine.Pages[0].DpiX;
                form.ProcessingPages = tempProcessingEngine.Pages;
            }

            return(form);
        }
Exemplo n.º 2
0
 internal DiskMasterFormExample(IMasterFormsRepository repository, string name, string path, IMasterFormsCategory parent)
 {
     _repository       = repository;
     _processingEngine = new FormProcessingEngine();
     _attributes       = null;
     _name             = name;
     _parent           = parent;
     _path             = path;
 }
Exemplo n.º 3
0
        // Read the fields of this master form
        public FormPages ReadFields()
        {
            if (!File.Exists(_path + ".xml"))
            {
                return(null);
            }
            _processingEngine.LoadFields(_path + ".xml");
            //to create new forms pages
            FormProcessingEngine tempProcessingEngine = new FormProcessingEngine();
            FormPages            formFields           = tempProcessingEngine.Pages;

            formFields.AddRange(_processingEngine.Pages);
            return(formFields);
        }
Exemplo n.º 4
0
        private bool StartUpEngines()
        {
            try
            {
                RecognitionEngine = new FormRecognitionEngine();
                ProcessingEngine  = new FormProcessingEngine();
                StartUpRasterCodecs();
                StartUpOcrEngine();
                //StartUpBarcodeEngine();
                //StartupTwain();
                FilledChar   = OcrEngine.ZoneManager.OmrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Filled);
                UnfilledChar = OcrEngine.ZoneManager.OmrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Unfilled);

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Error starting engines");
                return(false);
            }
        }
Exemplo n.º 5
0
        private void AddMasterFormPages(RasterImage imagesToAdd, DiskMasterForm currentform, string folderName)
        {
            try
            {
                DiskMasterForm            currentMasterForm = currentform;
                FormRecognitionAttributes attributes        = currentMasterForm.ReadAttributes();
                FormPages   formPages = currentMasterForm.ReadFields();
                RasterImage formImage = currentMasterForm.ReadForm();

                for (int i = 0; i < imagesToAdd.PageCount; i++)
                {
                    //Add each new page to the masterform by creating attributes for each page
                    imagesToAdd.Page = i + 1;
                    AddPageToMasterForm(imagesToAdd.Clone(), attributes, -1, null);
                }

                //Add image
                if (formImage != null)
                {
                    formImage.AddPages(imagesToAdd.CloneAll(), 1, imagesToAdd.PageCount);
                }
                else
                {
                    formImage = imagesToAdd.CloneAll();
                }

                //Only add processing pages for the new pages
                if (formPages != null)
                {
                    for (int i = 0; i < imagesToAdd.PageCount; i++)
                    {
                        formPages.Add(new FormPage(formPages.Count + 1, imagesToAdd.XResolution, imagesToAdd.YResolution));
                    }
                }
                else
                {
                    //No processing pages exist so we must create them
                    FormRecognitionEngine recognitionEngine    = SetupRecognitionEngine();
                    FormProcessingEngine  tempProcessingEngine = new FormProcessingEngine();
                    tempProcessingEngine.OcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false);
                    //tempProcessingEngine.BarcodeEngine = barcodeEngine;

                    for (int i = 0; i < recognitionEngine.GetFormProperties(attributes).Pages; i++)
                    {
                        tempProcessingEngine.Pages.Add(new FormPage(i + 1, imagesToAdd.XResolution, imagesToAdd.YResolution));
                    }

                    formPages = tempProcessingEngine.Pages;
                }

                //FormField newField = null;
                //AnnHiliteObject newObject = new AnnHiliteObject();
                //newField = new TextFormField();
                //newField.Name = "test";
                //newField.Bounds = new LogicalRectangle(50, 50, 50, 50, LogicalUnit.Pixel);

                //FormField newField1 = null;
                //AnnHiliteObject newObject1 = new AnnHiliteObject();
                //newField1 = new OmrFormField();
                //newField1.Name = "test1";
                //newField1.Bounds = new LogicalRectangle(50, 50, 50, 50, LogicalUnit.Pixel);

                //newObject.Tag = newField;
                //newObject1.Tag = newField1;
                //FormField currentField = newObject.Tag as FormField;
                //FormField currentField1 = newObject1.Tag as FormField;

                //formPages[0].Add(currentField);
                //formPages[0].Add(currentField1);

                currentMasterForm.WriteForm(formImage);
                currentMasterForm.WriteAttributes(attributes);
                currentMasterForm.WriteFields(formPages);
                DBHelper.UpdateTifPageCount(formImage.PageCount.ToString(), folderName);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        private void UpdateData()
        {
            var recognitionEngineVersion = FormRecognitionEngine.Version;

#if FOR_DOTNET4
            var originalFullTextSearchManager = recognitionEngine.FullTextSearchManager;
#endif

            try
            {
                if (!Directory.Exists(_txtSrcFolder.Text))
                {
                    Invoke((MethodInvoker) delegate { Messager.Show(this, "Please select valid folder", MessageBoxIcon.Error, MessageBoxButtons.OK); });
                    return;
                }

                // Set the data version to latest, we want to update the data to use the latest
                FormRecognitionEngine.Version = FormRecognitionEngine.LatestVersion;

                // Set the full text search engine
                DiskMasterFormsRepository workingRepository = new DiskMasterFormsRepository(_codecs, _txtSrcFolder.Text);

#if FOR_DOTNET4
                if (_cbUseFullTextSearch.Checked)
                {
                    DiskFullTextSearchManager fullTextSearchManager = new DiskFullTextSearchManager();
                    fullTextSearchManager.IndexDirectory    = Path.Combine(workingRepository.Path, "index");
                    recognitionEngine.FullTextSearchManager = fullTextSearchManager;
                }
#endif
                IMasterFormsCategory parentCategory = workingRepository.RootCategory;
                Invoke((MethodInvoker) delegate { _prgbar.Maximum = parentCategory.MasterForms.Count; });

                for (int i = 0; i < _prgbar.Maximum; i++)
                {
                    if (!_isRunning)
                    {
                        return;
                    }

                    Invoke((MethodInvoker) delegate { _prgbar.Value++; });

                    //Get the Original Attributes
                    DiskMasterForm            originalMasterForm = parentCategory.MasterForms[i] as DiskMasterForm;
                    FormRecognitionAttributes originalAttributes = originalMasterForm.ReadAttributes();
                    recognitionEngine.OpenMasterForm(originalAttributes);
                    recognitionEngine.CloseMasterForm(originalAttributes);

                    FormRecognitionOptions    options    = new FormRecognitionOptions();
                    FormRecognitionAttributes attributes = recognitionEngine.CreateMasterForm(parentCategory.MasterForms[i].Name, new Guid(), options);
                    recognitionEngine.CloseMasterForm(attributes);

                    IMasterForm newForm = parentCategory.AddMasterForm(attributes, null, (RasterImage)null);

                    DiskMasterForm currentMasterForm = parentCategory.MasterForms[i] as DiskMasterForm;
                    attributes = currentMasterForm.ReadAttributes();
                    FormPages   formPages = currentMasterForm.ReadFields();
                    RasterImage formImage = currentMasterForm.ReadForm();

                    for (int j = 0; j < formImage.PageCount; j++)
                    {
                        //Get the Page Recognition Options for the original Attributes
                        PageRecognitionOptions pageOptions = GetPageOptions(j, originalAttributes);

                        //Add each new page to the masterform by creating attributes for each page
                        formImage.Page = j + 1;
                        recognitionEngine.OpenMasterForm(attributes);
                        recognitionEngine.DeleteMasterFormPage(attributes, j + 1);
                        recognitionEngine.InsertMasterFormPage(j + 1, attributes, formImage.Clone(), pageOptions, null);
#if FOR_DOTNET4
                        if (_cbUseFullTextSearch.Checked)
                        {
                            recognitionEngine.UpsertMasterFormToFullTextSearch(attributes, "index", null, null, null, null);
                        }
#endif

                        recognitionEngine.CloseMasterForm(attributes);
                    }

                    FormProcessingEngine tempProcessingEngine = new FormProcessingEngine();
                    tempProcessingEngine.OcrEngine     = ocrEngine;
                    tempProcessingEngine.BarcodeEngine = barcodeEngine;

                    for (int j = 0; j < recognitionEngine.GetFormProperties(attributes).Pages; j++)
                    {
                        tempProcessingEngine.Pages.Add(new FormPage(j + 1, formImage.XResolution, formImage.YResolution));
                    }

                    formPages = tempProcessingEngine.Pages;
                    currentMasterForm.WriteAttributes(attributes);

                    currentMasterForm.WriteFields(parentCategory.MasterForms[i].ReadFields());
                }
#if FOR_DOTNET4
                if (recognitionEngine.FullTextSearchManager != null)
                {
                    recognitionEngine.FullTextSearchManager.Index();
                }
#endif
                System.Diagnostics.Process.Start(_txtSrcFolder.Text);
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate { Messager.Show(this, ex, MessageBoxIcon.Error); });
            }
            finally
            {
                // Restore the original version
                FormRecognitionEngine.Version = recognitionEngineVersion;
#if FOR_DOTNET4
                recognitionEngine.FullTextSearchManager = originalFullTextSearchManager;
#endif
                _isRunning = false;
                Invoke((MethodInvoker) delegate
                {
                    _prgbar.Value = 0;
                    UpdateControls();
                });
            }
        }