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.
IOcrEngine ocrEngine;
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, true);
ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime");
BarcodeEngine barcodeEngine = new BarcodeEngine();
AutoFormsEngine autoEngine = new AutoFormsEngine(repository,ocrEngine,barcodeEngine,30,80, true);
autoEngine.MinimumConfindenceRecognized = autoEngine.GetMinimumRecognizedConfidencePage();
AutoFormsRunResult result = autoEngine.RecognizeForm(image, null, null, null);
AutoFormsRunResult result = autoEngine.RecognizeForm(image, null);
How can I speed up Forms Recognition and Processing?
FormRecognitionEngin RecognitionEngine = new FormRecognitionEngine();
void SetObjectManagers(FormsRecognitionEngine RecognitionsEngine, bool enableDefault, bool enableOcr, bool enableBarcode)
{
if(enableDefault)
{
IOcrEngine FormsOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
FormsOcrEngine.Startip(null, null, null, @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime");
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);
}
}
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;
}
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);
}
FormProcessingEngineProcessingEngine = new FormProcessingEngine ();
IOcrEngine FormsOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
FormsOcrEngine.Startup(null, null, null, @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime");
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);
}
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);
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);
}
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);
}
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);
}