VintaSoft Imaging .NET SDK 12.5: Документация для .NET разработчика
В этом разделе
    Определение и распознавание документа, содержащего заполненную форму с OMR-метками
    В этом разделе
    Если вы хотите определить и распознать документ, содержащий заполненную форму с OMR-полями, вам необходимо выполнить следующие шаги:

    Вот C#/VB.NET код, демонстрирующий, как идентифицировать и распознать заполненную форму, содержащую OMR-метки.
    /// <summary>
    /// Recognizes the form with OMR fields.
    /// </summary>
    /// <param name="formRecognitionManager">The form recognition manager.</param>
    /// <param name="image">The image.</param>
    public static void RecognizeFormWithOmrFields(
        Vintasoft.Imaging.FormsProcessing.FormRecognitionManager formRecognitionManager,
        Vintasoft.Imaging.VintasoftImage image)
    {
        // if your form template contains OCR fields,
        // make sure OCR engine manager is initialized before recognition
        // (otherwise recognition will return null (Nothing)),
        // see OCR field recognition examples
    
        // recognize filled form in an image
        Vintasoft.Imaging.FormsProcessing.FormRecognitionResult recognitionResult = 
            formRecognitionManager.Recognize(image);
    
        // get the result of image comparison
        Vintasoft.Imaging.FormsProcessing.TemplateMatching.ImageImprintCompareResult imageCompareResult =
            recognitionResult.TemplateMatchingResult.ImageCompareResult;
        // if result is not reliable
        if (!imageCompareResult.IsReliable)
        {
            // matching template is not found
            System.Console.WriteLine("Matching template is not found.");
        }
        else
        {
            // get recognized page
            Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPage recognizedPage = 
                recognitionResult.RecognizedPage;
            // get form field count
            if (recognizedPage.Items.Count == 0)
            {
                System.Console.WriteLine("No form fields were recognized.");
            }
            else
            {
                System.Console.WriteLine(string.Format(
                    "Recognized form field count: {0}",
                    recognizedPage.Items.Count));
                // for each recognized form field
                foreach (Vintasoft.Imaging.FormsProcessing.FormRecognition.FormField recognizedField in recognizedPage.Items)
                {
                    if (recognizedField is Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrField)
                    {
                        Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrField omrField = 
                            (Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrField)recognizedField;
                        // write field info
                        System.Console.WriteLine(string.Format(
                            "  OMR field: name: {0}; state: {1}; confidence: {2:F1}%",
                            omrField.Name,
                            omrField.State,
                            omrField.Confidence * 100));
                    }
                }
            }
        }
    }
    
    ''' <summary>
    ''' Recognizes the form with OMR fields.
    ''' </summary>
    ''' <param name="formRecognitionManager">The form recognition manager.</param>
    ''' <param name="image">The image.</param>
    Public Shared Sub RecognizeFormWithOmrFields(formRecognitionManager As Vintasoft.Imaging.FormsProcessing.FormRecognitionManager, image As Vintasoft.Imaging.VintasoftImage)
        ' if your form template contains OCR fields,
        ' make sure OCR engine manager is initialized before recognition
        ' (otherwise recognition will return null (Nothing)),
        ' see OCR field recognition examples
    
        ' recognize filled form in an image
        Dim recognitionResult As Vintasoft.Imaging.FormsProcessing.FormRecognitionResult = formRecognitionManager.Recognize(image)
    
        ' get the result of image comparison
        Dim imageCompareResult As Vintasoft.Imaging.FormsProcessing.TemplateMatching.ImageImprintCompareResult = recognitionResult.TemplateMatchingResult.ImageCompareResult
        ' if result is not reliable
        If Not imageCompareResult.IsReliable Then
            ' matching template is not found
            System.Console.WriteLine("Matching template is not found.")
        Else
            ' get recognized page
            Dim recognizedPage As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPage = recognitionResult.RecognizedPage
            ' get form field count
            If recognizedPage.Items.Count = 0 Then
                System.Console.WriteLine("No form fields were recognized.")
            Else
                System.Console.WriteLine(String.Format("Recognized form field count: {0}", recognizedPage.Items.Count))
                ' for each recognized form field
                For Each recognizedField As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormField In recognizedPage.Items
                    If TypeOf recognizedField Is Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrField Then
                        Dim omrField As Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrField = DirectCast(recognizedField, Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrField)
                        ' write field info
                        System.Console.WriteLine(String.Format("  OMR field: name: {0}; state: {1}; confidence: {2:F1}%", omrField.Name, omrField.State, omrField.Confidence * 100))
                    End If
                Next
            End If
        End If
    End Sub
    

    Вот C#/VB.NET код, демонстрирующий, как идентифицировать и распознать заполненную форму, содержащую пузырьковый лист (группу OMR-меток).
    /// <summary>
    /// Recognizes the form with a group of marks (OMR bubbles).
    /// </summary>
    /// <param name="formRecognitionManager">The form recognition manager.</param>
    /// <param name="image">The image.</param>
    public static void RecognizeFormWithOmrFieldTables(
        Vintasoft.Imaging.FormsProcessing.FormRecognitionManager formRecognitionManager,
        Vintasoft.Imaging.VintasoftImage image)
    {
        // if your form template contains OCR fields,
        // make sure OCR engine manager is initialized before recognition
        // (otherwise recognition will return null (Nothing)),
        // see OCR field recognition examples
    
        // recognize filled form in an image
        Vintasoft.Imaging.FormsProcessing.FormRecognitionResult recognitionResult = 
            formRecognitionManager.Recognize(image);
    
        // get the result of image comparison
        Vintasoft.Imaging.FormsProcessing.TemplateMatching.ImageImprintCompareResult imageCompareResult =
            recognitionResult.TemplateMatchingResult.ImageCompareResult;
        // if result is not reliable
        if (!imageCompareResult.IsReliable)
        {
            // matching template is not found
            System.Console.WriteLine("Matching template is not found.");
        }
        else
        {
            // get recognized page
            Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPage recognizedPage = 
                recognitionResult.RecognizedPage;
            // get form field count
            if (recognizedPage.Items.Count == 0)
            {
                System.Console.WriteLine("No form fields were recognized.");
            }
            else
            {
                System.Console.WriteLine(string.Format(
                    "Recognized form field count: {0}",
                    recognizedPage.Items.Count));
                // for each recognized form field
                foreach (Vintasoft.Imaging.FormsProcessing.FormRecognition.FormField recognizedField in recognizedPage.Items)
                {
                    if (recognizedField is Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTable)
                    {
                        Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTable omrFieldTable = 
                            (Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTable)recognizedField;
                        Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTemplateTable omrTemplateTable =
                            omrFieldTable.FieldTemplate as Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTemplateTable;
                        // write field info
                        System.Console.WriteLine(string.Format(
                            "  OMR field table: name: {0}; value: {1}; confidence: {2:F1}%; row count: {3}; column count: {4}",
                            omrFieldTable.Name,
                            omrFieldTable.Value,
                            omrFieldTable.Confidence * 100,
                            omrTemplateTable.RowCount,
                            omrTemplateTable.ColumnCount));
                    }
                }
            }
        }
    }
    
    ''' <summary>
    ''' Recognizes the form with a group of marks (OMR bubbles).
    ''' </summary>
    ''' <param name="formRecognitionManager">The form recognition manager.</param>
    ''' <param name="image">The image.</param>
    Public Shared Sub RecognizeFormWithOmrFieldTables(formRecognitionManager As Vintasoft.Imaging.FormsProcessing.FormRecognitionManager, image As Vintasoft.Imaging.VintasoftImage)
        ' if your form template contains OCR fields,
        ' make sure OCR engine manager is initialized before recognition
        ' (otherwise recognition will return null (Nothing)),
        ' see OCR field recognition examples
    
        ' recognize filled form in an image
        Dim recognitionResult As Vintasoft.Imaging.FormsProcessing.FormRecognitionResult = formRecognitionManager.Recognize(image)
    
        ' get the result of image comparison
        Dim imageCompareResult As Vintasoft.Imaging.FormsProcessing.TemplateMatching.ImageImprintCompareResult = recognitionResult.TemplateMatchingResult.ImageCompareResult
        ' if result is not reliable
        If Not imageCompareResult.IsReliable Then
            ' matching template is not found
            System.Console.WriteLine("Matching template is not found.")
        Else
            ' get recognized page
            Dim recognizedPage As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormPage = recognitionResult.RecognizedPage
            ' get form field count
            If recognizedPage.Items.Count = 0 Then
                System.Console.WriteLine("No form fields were recognized.")
            Else
                System.Console.WriteLine(String.Format("Recognized form field count: {0}", recognizedPage.Items.Count))
                ' for each recognized form field
                For Each recognizedField As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormField In recognizedPage.Items
                    If TypeOf recognizedField Is Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTable Then
                        Dim omrFieldTable As Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTable = DirectCast(recognizedField, Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTable)
                        Dim omrTemplateTable As Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTemplateTable = TryCast(omrFieldTable.FieldTemplate, Vintasoft.Imaging.FormsProcessing.FormRecognition.Omr.OmrFieldTemplateTable)
                        ' write field info
                        System.Console.WriteLine(String.Format("  OMR field table: name: {0}; value: {1}; confidence: {2:F1}%; row count: {3}; column count: {4}", omrFieldTable.Name, omrFieldTable.Value, omrFieldTable.Confidence * 100, omrTemplateTable.RowCount, omrTemplateTable.ColumnCount))
                    End If
                Next
            End If
        End If
    End Sub