public AutoFormsEngine(
IMasterFormsRepository repository,
IOcrEngine ocrEngine,
BarcodeEngine barcodeEngine
)
repository
Repository of Master Forms.
ocrEngine
The Leadtools.Ocr.IOcrEngine that is used for optical character recognition and processing.
barcodeEngine
The Leadtools.Barcode.BarcodeEngine that is used for barcode recognition and processing.
It is the user's responsibility to dispose of this object when it is no longer needed by calling Dispose.
If ocrEngine is null, Leadtools.Forms.Recognition.Ocr.OcrObjectsManager will not be used for recognition and Leadtools.Forms.Processing.TextFormField and Leadtools.Forms.Processing.OmrFormField will not be processed.
If barcodeEngine is null, Leadtools.Forms.Recognition.Barcode.BarcodeObjectsManager will not be used for recognition and Leadtools.Forms.Processing.BarcodeFormField will not be processed.
The MinimumConfidenceRecognized is set to 90, MinimumConfidenceKnownForm is set to 30, and RecognizeFirstPageOnly is set to false.
The recognition Object Managers will be set to the managers used to generate the Master Forms in the repository.
Important: Different OCR engines might have slight differences in form alignment and recognition. Therefore, it is best to use the same Leadtools.Ocr.OcrEngineType when generating the master forms and when recognizing and processing forms.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Common;
using Leadtools.Forms.Auto;
using Leadtools.Document;
using Leadtools.Ocr;
using Leadtools.Forms.Recognition;
using Leadtools.Forms.Processing;
using Leadtools.Barcode;
using Leadtools.Forms;
public RasterCodecs Codecs;
public string FormFileName;
public void MyPageRequestCallback(PageRequestCallbackData data)
{
data.Page = Codecs.Load(FormFileName, 1, CodecsLoadByteOrder.Bgr, data.FormPageNumber, data.FormPageNumber);
}
public void AutoFormRunAutomatic()
{
string root = Path.Combine(LEAD_VARS.ImagesDir, @"Forms\FormsDemo\OCR_Test");
RasterCodecs codecs = new RasterCodecs();
//create repository
DiskMasterFormsRepository repository = new DiskMasterFormsRepository(codecs, root);
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);
BarcodeEngine barcodeEngine = new BarcodeEngine();
//create AutoForm Engine
AutoFormsEngine autoEngine = new AutoFormsEngine(repository, ocrEngine, barcodeEngine);
//set the flag to process the first page only
autoEngine.RecognizeFirstPageOnly = true;
autoEngine.MinimumConfidenceKnownForm = 40;
//calculate the minimum confidence recognized form according to the correlation between the master forms in the repository
autoEngine.MinimumConfidenceRecognized = autoEngine.GetMinimumRecognizedConfidenceForm();
Codecs = codecs;
FormFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Forms\Forms to be Recognized\OCR\FCC-107_OCR_Filled.tif");
//load the first page of the image
RasterImage form = codecs.Load(FormFileName, 1, CodecsLoadByteOrder.Bgr, 1, 1);
//recognize and process the form
AutoFormsRunResult result = autoEngine.Run(form, MyPageRequestCallback, null, null);
if (result == null)
return;
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime";
}