Frequently Asked Questions
Table of Contents
General
Generating Master Forms
Low Level
RasterCodecs codecs = new RasterCodecs(); DiskMasterFormsRepository repository = new DiskMasterFormsRepository(codecs, rootFolderPath);
Initialize a multithread AutoForms engine by creating multiple OCR engines and pass them to the AutoFormEngine constructor.
List<IOcrEngine> ocrEngine = new List<IOcrEngine>(); IOcrEngine ocrEngine; //to use four threads int numberOfThreads = 4; for(int i = 0; i < numberOfThreads; i++) { ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Professional, true); ocrEngine.Startup(null, null, null); ocrEngine.Add(ocrEngine); } BarcodeEnigne barcodeEngine = new BarcodeEngine(); AutoFormsEngine autoEngine = new AutoFormsEngine(repository, ocrEngine, barcodeEngine, 30, 80, true);
autoEngine.MinimumConfindenceRecognized = autoEngine.GetMinimumRecognizedConfidencePage();
IOcrEngine ocrEngine; ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Professional, true); ocrEngine.Startup(null, null, null, null); BarcodeEngine barcodeEngine = new BarcodeEngine(); AutoFormsEngine autoEngine = new AutoFormsEngine(repository,ocrEngine,barcodeEngine,30,80, true);
AutoFormsRunResult result = autoEngine.RecognizeForm(image, null, null, null);
AutoFormsRunResult result = autoEngine.RecognizeForm(image, null);
FormRecognitionEngin RecognitionEngine = new FormRecognitionEngine();
Set the ObjectsManagers of the FormRecognitionEngine Recognition Engine according to the anticipated form set. For example, if all forms have a barcode label that identifies them, then BarcodeObjectsManager would be a good choice because it is very fast and yet very accurate. If not all forms have barcode labels you can use either OcrObjectsManager alone or OcrObjectsManager and BarcodeObjectsManager together.
If the forms being detected are simple and can be distinguished based on the lines and inverted text objects inside them, then you may use Leadtools.Forms.Recognition.DefaultObjectsManager alone.
Select the object manager when forms processing is going to be performed after the recognition as follows:
void SetObjectManagers(FormsRecognitionEngine RecognitionsEngine, bool enableDefault, bool enableOcr, bool enableBarcode) { if(enableDefault) { IOcrEngine FormsOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false); FormsOcrEngine.Startip(null, null, null); OcrObjectsManager ocrObejectManager = new OcrObjectsManager(FormsOcrEngine); ocrObjectManager.Engine = FormsOcrEngine; RecognitionEngine.ObjectsManagers.Add(ocrObejectManager); } if(enableBarcode) { BarcodeEngine FormsBarcodeEngine = new BarcodeEngine(); BarcodeObjectsManager barcodeObjectManager = new BarcodeObjectsManager(FormsBarcodeEngine); barcodeObjectManager.Engine = FormsBarcodeEngine; RecognitionEngine.ObjectsManagers.Add(barcodeObjectManager); } }
You can create a Master Form and then modify (add/delete) the form pages at a later time. Notice that a form's attribute set is like a file: you have to open it before modifying it and close it after you finish modifying it. Do that by either:
1. Create Master Form Attributes
public FormRecognitionAttributes CreateMasterForm(string name, FormRecognitionEngine RecognitionEngine) { FormRecognitionAttributes attributes = RecognitionEngine.CreateMasterForm(name, Guid.Empty, null); RecognitionEngine.CloseMasterForm(attributes); return attributes; }
2. Add Pages to an already existing Master Form Attribute
public void AddPagesToMasterForm (RasterImage image, FormRecognitionAttributes masterFormAttributes, FormRecognitionEngine RecognitionEngine) { RecognitionEngine.OpenMasterForm(masterFormAttributes); int saveCurrentPageIndex = image.Page; for(int i = 0; i < image.PageCount; i++) { image.Page = i + 1; RecognitionEngine.AddMasterFormPage(masterFormAttributes, image, null); } image.Page = saveCurrentPageIndex; RecognitionEngine.CloseMasterForm(masterFormAttributes); }
3. Create a Master Form Attributes and add the pages at the same time
public FormRecognitionAttributes CreateMasterForm(string name, RasterImage image, FormRecognitionEngine RecognitionEngine) { FormRecognitionAttributes masterFormAttributes = RecognitionEngine.CreateMasterForm(name, Guid.Empty, null); int saveCurrentPageIndex = image.Page; for(int i = 0; i < image.PageCount; i++) { image.Page = i + 1; RecognitionEngine.AddMasterFormPage(masterFormAttributes, image, null); } image.Page = saveCurrentPageIndex; RecognitionEngine.CloseMasterForm(masterFormAttributes); return attributes; }
public FormRecognitionAttributes CreateMasterForm(string name, FormRecognitionEngine RecognitionEngine) { FormRecognitionAttributes attributes = RecognitionEngine.CreateMasterForm(name, Guid.Empty, null); RecognitionEngine.CloseMasterForm(attributes); return attributes; }
public void AddPagesToMasterForm (RasterImage image FormRecognitionAttributes masterFormAttributes, FormRecognitionEngine RecognitionEngine) { RecognitionEngine.OpenMasterForm(masterFormAttributes); int saveCurrentPageIndex = image.Page; for(int i = 0; i < image.PageCount; i++) { image.Page = i + 1; RecognitionEngine.AddMasterFormPage(masterFormAttributes, image, null); } image.Page = saveCurrentPageIndex; RecognitionEngine.CloseMasterForm(masterFormAttributes); }
public void SaveAttributes(FormRecognitionAttributes attributes, string attributesFileName) { byte[] data = attributes.GetData(); File.WriteAllBytes(attributesFileName, data); }
public void LoadMasterFormAttributes(FormRecognitionAttributes attributes, string attributesFileName) { byte[] data = File.ReadAllBytes(attributesFileName); attributes.SetData(data); }
Initialize an engine then add Ocr and Barcode engines
FormProcessingEngineProcessingEngine = new FormProcessingEngine (); IOcrEngine FormsOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false); FormsOcrEngine.Startup(null, null, null); ProcessingEngine.OcrEngine = FormsOcrEngine; ProcessingEngine.BarcodeEngine = FormsBarcodeEngine;
Public void CreateTextField(List<FormField> fields, string name, LogicalRectangle bounds) { TextFormField text = new TextFormField(); text.Name = name; text.Bounds = bounds; fields.Add(text); }
Public void CreateOmrField(List<FormField> fields, string name, LogicalRectangle bounds) { OmrFormField omr = new OmrFormField(); omr.Name = name; omr.Bounds = bounds; fields.Add(omr); }
Public void CreateBarcodeField(List<FormField> fields, string name, LogicalRectangle bounds) { BarcodeFormField barcode = new BarcodeFormField(); barcode.Name = name; barcode.Bounds = bounds; fields.Add(barcode); }
Public void CreateImageField(List<FormField> fields, string name, LogicalRectangle bounds) { ImageFormField image = new ImageFormField(); image.Name = name; image.Bounds = bounds; fields.Add(image); }
This will create a page for the fields. The page number and the resolution of the image that the fields are associated with should be known.
Public FormPage AddFieldsToFormPage(List<FormField> fields, int pageNumber, int dpiX, int dpiY) { FormPage formPage = new FormPage(pageNumber, dpiX, dpiY); formPage.AddRange(fields); return formPage; }
Public void AddPageToProcessingPages(FormPage formPage, FormProcessingEngineProcessingEngine) { ProcessingEngine.Pages.Add(formPage); }
ProcessingEngine.SaveFields(fileName);
The fields will be load in the Processing Engine Pages.
ProcessingEngine.LoadFields(fileName);
It is a group of classes and methods that allow users to build their own algorithms for recognition and processing and to implement their own multithreading processes. The speed of recognition and processing may be slow depending on the implementation and the performance of the algorithm.
You can create a Master Form and then modify (add or delete) the form pages at a later time. Notice that a form's attributes are like a file: you have to open it before modifying it and close it after you finish. You can do that by either:
public FormRecognitionAttributes CreateForm(FormRecognitionEngine RecognitionEngine) { FormRecognitionAttributes attributes = RecognitionEngine.CreateForm(null); RecognitionEngine.CloseForm(attributes); return attributes; }
Add Pages to an existing Form Attributes
public void AddPagesToForm (RasterImage image, FormRecognitionAttributes formAttributes, FormRecognitionEngine RecognitionEngine) { RecognitionEngine.OpenForm(masterFormAttributes); int saveCurrentPageIndex = image.Page; for(int i = 0; i < image.PageCount; i++) { image.Page = i + 1; RecognitionEngine.AddFormPage(formAttributes, image, null); } image.Page = saveCurrentPageIndex; RecognitionEngine.CloseForm(masterFormAttributes); }
public FormRecognitionAttributes CreateForm(FormRecognitionEngine RecognitionEngine) { FormRecognitionAttributes attributes = RecognitionEngine.CreateForm(null); RecognitionEngine.CloseForm(attributes); return attributes; }
public void AddPagesToForm (RasterImage image, FormRecognitionAttributes formAttributes, FormRecognitionEngine RecognitionEngine) { RecognitionEngine.OpenForm(masterFormAttributes); saveCurrentPageIndex = image.Page; for(int i = 0; i < image.PageCount; i++) { image.Page = i + 1; RecognitionEngine.AddFormPage(formAttributes, image, null); } image.Page = saveCurrentPageIndex; RecognitionEngine.CloseForm(masterFormAttributes; }
FormRecognitionResult CompareForm(FormRecognitionAttributes master, FormRecognitionAttributes form, FormRecognitionEngine RecognitionEngine) { return RecognitionEngine.CompareForm(master, form, null); }
Note: When there is a list of Master Forms, the Form Attributes should be compared to each Master Form Attributes. The Master Form with maximum confidence result is considered to be the type of the Form Attributes. If the maximum confidence is very small (for example, less than 20) then the Form is considered to be of unknown type.
PageRecognitionResult CompareForm(FormRecognitionAttributes master, int masterPage, FormRecognitionAttributes form, int formPage, FormRecognitionEngine RecognitionEngine) { return RecognitionEngine.ComparePage(master, 1, form, 1); }
Note: This is very helpful in speeding up the recognition by comparing the first page only if Master Forms do not have the same first page. This comparison is also very useful for determining the form type for a single page.
Get Form Alignment
IList<PageAlignment>GetFormAlignment(FormRecognitionAttributes master, FormRecognitionAttributes form, FormRecognitionEngine RecognitionEngine) { return RecognitionEngine.GetPageAlignment(master, masterPage, form, formPage); }
Get Page Alignment
PageAlignment GetPageAlignment(FormRecognitionAttributes master, int masterPage, FormRecognitionAttributes form,int formPage, FormRecognitionEngine RecognitionEngine) { return RecognitionEngine.GetPageAlignment(master, masterPage, form, formPage); }
Get Pages Alignment from FormRecognitionResult
List<PageAlignment>GetFormAlignment(FormRecognitionResult results) { List<PageAlignment> alignment = new List<PageAlignment>(); for(int i = 0; i < form.Result.PageResults.Count; i++) alignment.Add(results.PageResults[i].Alignment); return alignment; }
Public void AddPageToProcessingPages(FormProcessingEngine ProcessingEngine, RasterImage form, IList<PageAlignment> formAlignment) { ProcessingEngine.Process(form, formAlignment); }