当前位置: 首页>>代码示例>>C#>>正文


C# IEngine.CreateTrainingBatch方法代码示例

本文整理汇总了C#中IEngine.CreateTrainingBatch方法的典型用法代码示例。如果您正苦于以下问题:C# IEngine.CreateTrainingBatch方法的具体用法?C# IEngine.CreateTrainingBatch怎么用?C# IEngine.CreateTrainingBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEngine的用法示例。


在下文中一共展示了IEngine.CreateTrainingBatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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 );
        }
开发者ID:DominatorCode,项目名称:FlexiCapture-Code-Snippets--C--,代码行数:74,代码来源:Advanced+techniques.cs

示例2: 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 );
        }
开发者ID:DominatorCode,项目名称:FlexiCapture-Code-Snippets--C--,代码行数:74,代码来源:Advanced+techniques.cs


注:本文中的IEngine.CreateTrainingBatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。