How do I initialize a repository?
string rootFolderPath = @"C:\Users\Public\Documents\LEADTOOLS Images\Forms\MasterForm Sets\OCR\";
RasterCodecs codecs = new RasterCodecs();
DiskMasterFormsRepository repository = new DiskMasterFormsRepository(codecs, rootFolderPath);
How do I initialize a multi-threaded AutoForms engine? Initialize a multi-threaded AutoForms engine by creating the main OCR engine and passing it to the AutoFormEngine constructor. For sample code on Multi-threaded AutoForms engine, refer to Programming With the LEADTOOLS Forms Recognition Processing Engine.
How do I initialize a non-threaded AutoForms engine?
IOcrEngine ocrEngine;
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, true);
ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime");
BarcodeEngine barcodeEngine = new BarcodeEngine();
AutoFormsEngine autoEngine = new AutoFormsEngine(repository,ocrEngine,barcodeEngine,30,80, true);
How do I find and set the best minimum confidence value to speed up the recognition process over my Master Forms repository?
autoEngine.MinimumConfindenceRecognized = autoEngine.GetMinimumRecognizedConfidencePage();
How do I recognize and process a Form image at the same time?
AutoFormsRunResult result = autoEngine.RecognizeForm(image, null, null, null);
How do I recognize a Form image only?
AutoFormsRunResult result = autoEngine.RecognizeForm(image, null);
How can I speed up Forms Recognition and Processing?
How do I initialize the Forms Recognition engine?
FormRecognitionEngin RecognitionEngine = new FormRecognitionEngine();
How do I set the ObjectsManagers for the recognition engine? 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.LEAD, false);
FormsOcrEngine.Startip(null, null, null, @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime");
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);
}
}
How do I create Master Form Attributes? 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:
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);
}
Creating a Master Form Attributes and adding 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;
}
How do I create a Master Form Attributes without modification?
public FormRecognitionAttributes CreateMasterForm(string name, FormRecognitionEngine RecognitionEngine)
{
FormRecognitionAttributes attributes = RecognitionEngine.CreateMasterForm(name, Guid.Empty, null);
RecognitionEngine.CloseMasterForm(attributes);
return attributes;
}
How do I add pages to an existing Master Form 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);
}
How do I save a form's Attributes?
public void SaveAttributes(FormRecognitionAttributes attributes, string attributesFileName)
{
byte[] data = attributes.GetData();
File.WriteAllBytes(attributesFileName, data);
}
How do I load a form's Attributes?
public void LoadMasterFormAttributes(FormRecognitionAttributes attributes, string attributesFileName)
{
byte[] data = File.ReadAllBytes(attributesFileName);
attributes.SetData(data);
}
How do I initialize a processing engine? Initialize an engine and then add Ocr and Barcode engines
FormProcessingEngineProcessingEngine = new FormProcessingEngine ();
IOcrEngine FormsOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false);
FormsOcrEngine.Startup(null, null, null, @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime");
ProcessingEngine.OcrEngine = FormsOcrEngine;
ProcessingEngine.BarcodeEngine = FormsBarcodeEngine;
public void CreateTextField(List<FormField> fields, string name, LeadRect bounds)
{
TextFormField text = new TextFormField();
text.Name = name;
text.Bounds = bounds;
fields.Add(text);
}
public void CreateOmrField(List<FormField> fields, string name, LeadRect bounds)
{
OmrFormField omr = new OmrFormField();
omr.Name = name;
omr.Bounds = bounds;
fields.Add(omr);
}
How do I create a Barcode Field?
public void CreateBarcodeField(List<FormField> fields, string name, LeadRect bounds)
{
BarcodeFormField barcode = new BarcodeFormField();
barcode.Name = name;
barcode.Bounds = bounds;
fields.Add(barcode);
}
How do I create an Image Field?
public void CreateImageField(List<FormField> fields, string name, LeadRect bounds)
{
ImageFormField image = new ImageFormField();
image.Name = name;
image.Bounds = bounds;
fields.Add(image);
}
How do I add fields to a page's fields? 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;
}
How do I add page fields to processing engine pages?
public void AddPageToProcessingPages(FormPage formPage, FormProcessingEngineProcessingEngine)
{
ProcessingEngine.Pages.Add(formPage);
}
How do I save Processing Fields?
ProcessingEngine.SaveFields(fileName);
How do I load Processing Fields? The fields will be load in the Processing Engine Pages.
ProcessingEngine.LoadFields(fileName);
What is Low Level Form Recognition and Processing? 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.
How do I create and add pages to a Form's Attributes? 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;
}
Adding 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);
}
How do I create a Form's Attributes?
public FormRecognitionAttributes CreateForm(FormRecognitionEngine RecognitionEngine)
{
FormRecognitionAttributes attributes = RecognitionEngine.CreateForm(null);
RecognitionEngine.CloseForm(attributes);
return attributes;
}
How do I add pages to an existing Form's 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;
}
How do I compare a Form to a Master Form?
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);
}
How do I Get Form Alignment? Get Form Alignment
IList<PageAlignment> GetFormAlignment(FormRecognitionAttributes master, FormRecognitionAttributes form, FormRecognitionEngine RecognitionEngine)
{
return RecognitionEngine.GetPageAlignment(master, masterPage, form, formPage);
}
PageAlignment GetPageAlignment(FormRecognitionAttributes master, int masterPage, FormRecognitionAttributes form,int formPage, FormRecognitionEngine RecognitionEngine)
{
return RecognitionEngine.GetPageAlignment(master, masterPage, form, formPage);
}
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);
}