本文整理汇总了C#中IEngine.CreateDocumentDefinitionFromAFL方法的典型用法代码示例。如果您正苦于以下问题:C# IEngine.CreateDocumentDefinitionFromAFL方法的具体用法?C# IEngine.CreateDocumentDefinitionFromAFL怎么用?C# IEngine.CreateDocumentDefinitionFromAFL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEngine
的用法示例。
在下文中一共展示了IEngine.CreateDocumentDefinitionFromAFL方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Creating_a_Document_Definition_from_a_FlexiLayout
// USE CASE: Creating a Document Definition from a FlexiLayout (*.afl)
public static void Creating_a_Document_Definition_from_a_FlexiLayout( IEngine engine )
{
trace( "Create a Document Definition from an *.afl file..." );
string flexibleDescriptionFilePath = SamplesFolder + "\\SampleMisc\\Invoice_eng.afl";
IDocumentDefinition newDefinition = engine.CreateDocumentDefinitionFromAFL( flexibleDescriptionFilePath, "English" );
// You can save the new Document Definition to a file or use it from memory
traceBegin("Use the Document Definition in FlexiCaptureProcessor...");
IFlexiCaptureProcessor processor = engine.CreateFlexiCaptureProcessor();
processor.AddDocumentDefinition( newDefinition );
// Add images for a single document
processor.AddImageFile( SamplesFolder + "\\SampleImages\\Invoices_1.tif" );
// Recognize the document and check the result
IDocument document = processor.RecognizeNextDocument();
assert( document != null );
assert( document.DocumentDefinition != null );
assert( document.Pages.Count == 1 );
// Export the result
processor.ExportDocumentEx( document, SamplesFolder + "\\FCEExport", "Invoice", null );
traceEnd( "OK" );
}
示例2: Creating_a_Document_Definition_by_training_on_a_set_of_images_LPAREN2RPAREN
// USE CASE: Creating a Document Definition by training on a set of images
public static void Creating_a_Document_Definition_by_training_on_a_set_of_images_LPAREN2RPAREN( IEngine engine )
{
string rootFolder = SamplesFolder + "\\SampleImages\\Training\\ISBN";
string batchFolder = rootFolder + "\\_TrainingBatch";
if( System.IO.Directory.Exists( batchFolder ) ) {
// Delete the existing training batch
System.IO.Directory.Delete( batchFolder, true );
}
trace( "Create training batch and populate it with images..." );
ITrainingBatch trainingBatch = engine.CreateTrainingBatch( batchFolder, "English" );
try {
ITrainingDefinition newDefinition = trainingBatch.Definitions.AddNew( "ISBN" );
trainingBatch.AddImageFile( rootFolder + "\\00.jpg" );
trainingBatch.AddImageFile( rootFolder + "\\01.jpg" );
traceBegin( "The user iterates through the added images until all the pages have been submitted for training..." );
ITrainingPage page = trainingBatch.PrepareNextPageNotSubmittedForTraining();
while( page != null ) {
traceBegin( page.ID.ToString() + "..." );
// The user can 'draw' fields and references on any page while inside this loop. Any modification in the document definition will reset
// the 'verified' flag for all pages and the loop will automatically reiterate through all pages. In this sample we try to emulate the
// user 'drawing' fields on the first page.
if( page == trainingBatch.Pages[0] ) {
// On the fist page we 'look' for known text strings and 'draw' fields around them
for( int j = 0; j < page.ImageObjects.Count; j++ ) {
ITrainingImageObject obj = page.ImageObjects[j];
string text = obj.RecognizedText;
if( text == "978-1-4095-3439-6" ) {
// We want to extact this field. Create a data field and define its geometry on the current page.
ITrainingField isbnField = newDefinition.Fields.AddNew( "ISBN", TrainingFieldTypeEnum.TFT_Field );
page.SetFieldBlock( isbnField, obj.Region );
break;
}
}
for( int j = 0; j < page.ImageObjects.Count; j++ ) {
ITrainingImageObject obj = page.ImageObjects[j];
string text = obj.RecognizedText;
if( text == "ISBN" ) {
// We want to use this text for reference. Create a reference element and define its geometry on the current page.
ITrainingField isbnTag = newDefinition.Fields.AddNew( "ISBNTag", TrainingFieldTypeEnum.TFT_ReferenceText );
page.SetFieldBlock( isbnTag, obj.Region );
break;
}
}
// We assume that we have succeeded in defining two items
assert( newDefinition.Fields.Count == 2 );
}
// After the user has defined the layout (or verified the automatically computed layout for subsequent pages), he must submit
// the result for training. In this sample we assume that the computed layout is always correct, so just mark the page as verified
// and ready for training.
trainingBatch.SubmitPageForTraining( page );
// Fetch the next page that requires attention. The method will return null when all the pages have been verified and submitted for training.
page = trainingBatch.PrepareNextPageNotSubmittedForTraining();
traceEnd( "OK" );
}
traceEnd( "OK" );
trace( "Export to AFL..." );
newDefinition.ExportToAFL( batchFolder + "\\NewTemplate.afl" );
} finally {
trainingBatch.Close();
}
trace( "Create document definition." );
IDocumentDefinition newDocumentDefinition = engine.CreateDocumentDefinitionFromAFL( batchFolder + "\\NewTemplate.afl", "English" );
trace( "Use the new document definition with FlexiCapture Processor." );
CheckTrainedDocumentDefinition( engine, newDocumentDefinition, rootFolder );
}
示例3: Configuring_fields_for_better_recognition_results
// USE CASE: Configuring fields for better recognition results
public static void Configuring_fields_for_better_recognition_results( IEngine engine )
{
trace( "Create a Document Definition from a FlexiLayout..." );
IDocumentDefinition newDefinition = engine.CreateDocumentDefinitionFromAFL( SamplesFolder + "\\SampleMisc\\Invoice_eng.afl", "English" );
assert( newDefinition != null );
trace( "Configure data types..." );
setFieldValueType( newDefinition, "InvoiceDate", FieldValueTypeEnum.FVT_DateTime );
setFieldValueType( newDefinition, "Quantity", FieldValueTypeEnum.FVT_Number );
setFieldValueType( newDefinition, "UnitPrice", FieldValueTypeEnum.FVT_Currency );
setFieldValueType( newDefinition, "Total", FieldValueTypeEnum.FVT_Currency );
setFieldValueType( newDefinition, "TotalAmount", FieldValueTypeEnum.FVT_Currency );
trace( "Configure recognition languages for text fields ..." );
IFieldDefinition fieldDef = findFieldDef( newDefinition, "InvoiceNumber" );
assert( fieldDef != null );
ITextRecognitionParams textParams = fieldDef.RecognitionParams.AsTextParams();
ILanguage newLanguage = textParams.CreateEmbeddedLanguageByDataType( FieldValueTypeEnum.FVT_DateTime );
textParams.Language = newLanguage;
newLanguage = textParams.CreateEmbeddedLanguage( textParams.Language.Type, textParams.Language );
assert( newLanguage != textParams.Language );
assert( newLanguage.LanguageCategory == LanguageCategoryEnum.LC_DataType );
assert( newLanguage.DatatypeCategory == DatatypeCategoryEnum.TC_DateTime );
textParams.Language = newLanguage;
newLanguage = textParams.CreateEmbeddedLanguage( LanguageTypeEnum.LT_Group, null );
newLanguage.AsGroupLanguage().Add( engine.PredefinedLanguages.FindLanguage( "English" ) );
newLanguage.AsGroupLanguage().Add( engine.PredefinedLanguages.FindLanguage( "Russian" ) );
textParams.Language = newLanguage;
assert( textParams.Language.Type == LanguageTypeEnum.LT_Group );
assert( textParams.Language.AsGroupLanguage().Count == 2 );
assert( textParams.Language.AsGroupLanguage().Item( 0 ).InternalName == "English" );
assert( textParams.Language.AsGroupLanguage().Item( 1 ).InternalName == "Russian" );
newLanguage = textParams.CreateEmbeddedLanguage( LanguageTypeEnum.LT_Simple, null );
newLanguage.AsSimpleLanguage().set_LetterSet( LanguageLetterSetEnum.LLS_Alphabet, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
newLanguage.AsSimpleLanguage().RegularExpression = "[A-Z]{1-}";
textParams.Language = newLanguage;
assert( textParams.Language.AsSimpleLanguage().RegularExpression.Length > 0 );
newLanguage = textParams.CreateEmbeddedLanguage( LanguageTypeEnum.LT_Simple, engine.PredefinedLanguages.FindLanguage( "English" ) );
assert( newLanguage.AsSimpleLanguage().UsePredefinedDictionary == true );
assert( newLanguage.AsSimpleLanguage().UseUserDefinedDictionary == false );
assert( newLanguage.AsSimpleLanguage().UserDefinedDictionary == null );
newLanguage.AsSimpleLanguage().UseUserDefinedDictionary = true;
FCEngine.IDictionary dictionary = newLanguage.AsSimpleLanguage().UserDefinedDictionary;
assert( dictionary != null );
assert( dictionary.WordsCount == 0 );
dictionary.AddWord( "ONE", 1 );
dictionary.AddWord( "TWO", 1 );
dictionary.AddWord( "THREE", 1 );
assert( dictionary.WordsCount == 3 );
IEnumDictionaryWords enumWords = dictionary.EnumWords();
for( int i = 0; i < 10; i++ ) {
int confidence = 0;
string word = enumWords.Next( out confidence );
if( confidence == 0 ) {
break;
}
trace( word );
}
textParams.Language = newLanguage;
trace( "Check the Document Definition..." );
assert( newDefinition.Check() == true );
traceBegin("Use the Document Definition in FlexiCaptureProcessor...");
IFlexiCaptureProcessor processor = engine.CreateFlexiCaptureProcessor();
processor.AddDocumentDefinition( newDefinition );
// Add images for a single document
processor.AddImageFile( SamplesFolder + "\\SampleImages\\Invoices_1.tif" );
// Recognize the document
IDocument document = processor.RecognizeNextDocument();
assert( document != null );
assert( document.DocumentDefinition != null );
assert( document.Pages.Count == 1 );
processor.ExportDocumentEx( document, SamplesFolder + "\\FCEExport", "Invoice", null );
traceEnd( "OK" );
}
示例4: Creating_a_Document_Definition_by_training_on_a_set_of_images
// USE CASE: Creating a Document Definition by training on a set of images
public static void Creating_a_Document_Definition_by_training_on_a_set_of_images( IEngine engine )
{
string rootFolder = SamplesFolder + "\\SampleImages\\Training\\ISBN";
string batchFolder = rootFolder + "\\_TrainingBatch";
if( System.IO.Directory.Exists( batchFolder ) ) {
// Delete the existing training batch
System.IO.Directory.Delete( batchFolder, true );
}
trace( "Create training batch and populate it with images..." );
ITrainingBatch trainingBatch = engine.CreateTrainingBatch( batchFolder, "English" );
try {
ITrainingDefinition newDefinition = trainingBatch.Definitions.AddNew( "ISBN" );
trainingBatch.AddImageFile( rootFolder + "\\00.jpg" );
trainingBatch.AddImageFile( rootFolder + "\\01.jpg" );
trace( "Use the first page to define document structure..." );
ITrainingPage firstPage = trainingBatch.Pages[0];
// Each page must be prepared before trying to work with its layout. At this stage the page is analyzed
// and primitive image objects are extracted (which can be used as helpers in user imterface).
// Than an attempt is made to predict the page layout based on the layout of verified pages if any.
firstPage.PrepareLayout();
// At this point the user must draw boxes for fields and references. In this sample we try to emulate this
// behavior by 'looking' for known text strings and 'drawing' fields around them.
for( int j = 0; j < firstPage.ImageObjects.Count; j++ ) {
ITrainingImageObject obj = firstPage.ImageObjects[j];
string text = obj.RecognizedText;
if( text == "978-1-4095-3439-6" ) {
// We want to extact this field. Create a data field and define its geometry on the current page.
ITrainingField isbnField = newDefinition.Fields.AddNew( "ISBN", TrainingFieldTypeEnum.TFT_Field );
firstPage.SetFieldBlock( isbnField, obj.Region );
break;
}
}
for( int j = 0; j < firstPage.ImageObjects.Count; j++ ) {
ITrainingImageObject obj = firstPage.ImageObjects[j];
string text = obj.RecognizedText;
if( text == "ISBN" ) {
// We want to use this text for reference. Create a reference element and define its geometry on the current page.
ITrainingField isbnTag = newDefinition.Fields.AddNew( "ISBNTag", TrainingFieldTypeEnum.TFT_ReferenceText );
firstPage.SetFieldBlock( isbnTag, obj.Region );
break;
}
}
assert( newDefinition.Fields.Count == 2 );
// Now that we are done with this page, mark it as verified and ready for training.
trainingBatch.SubmitPageForTraining( firstPage );
traceBegin( "Verify the computed layout on the remaining pages..." );
for( int i = 1; i < trainingBatch.Pages.Count; i++ ) {
traceBegin( i.ToString() + "..." );
ITrainingPage page = trainingBatch.Pages[i];
page.PrepareLayout();
// At this point the user must verify and correct the computed layout. In this sample we assume that
// the computed layout is correct, so we just mark the page as verified and ready for training.
trainingBatch.SubmitPageForTraining( page );
traceEnd( "OK" );
}
traceEnd( "OK" );
trace( "Export to AFL..." );
newDefinition.ExportToAFL( batchFolder + "\\NewTemplate.afl" );
} finally {
trainingBatch.Close();
}
trace( "Create document definition." );
IDocumentDefinition newDocumentDefinition = engine.CreateDocumentDefinitionFromAFL( batchFolder + "\\NewTemplate.afl", "English" );
trace( "Use the new document definition with FlexiCapture Processor." );
CheckTrainedDocumentDefinition( engine, newDocumentDefinition, rootFolder );
}