VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
In This Topic
    Identify and recognize a document that contains completed form with barcodes
    In This Topic
    If you want to identify and recognize document that contains completed form with barcodes, you need to do the following steps:
    Here is C#/VB.NET code that demonstrates how to identify and recognize a complteted form that contains barcodes.
    /// <summary>
    /// Recognizes the form with barcode fields.
    /// </summary>
    /// <param name="formRecognitionManager">The form recognition manager.</param>
    /// <param name="image">The image.</param>
    /// <remarks>
    /// The BarcodeField and BarcodeFieldTemplate classes are available
    /// in the VintaSoft Forms Processing Demo source codes.
    /// </remarks>
    public static void RecognizeFormWithBarcodeFields(
        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)
                {
                    // an example of BarcodeField class implementation can be found
                    // in the VintaSoft Forms Processing Demo source codes
                    if (recognizedField is BarcodeField)
                    {
                        BarcodeField barcodeField = (BarcodeField)recognizedField;
                        // write field info
                        System.Console.WriteLine(string.Format(
                            "  Barcode field: name: {0}; type: {1}; value: {2}; confidence: {3:F1}%",
                            barcodeField.Name,
                            barcodeField.BarcodeInfo.BarcodeType,
                            barcodeField.Value,
                            barcodeField.Confidence * 100));
                    }
                }
            }
        }
    }
    
    ''' <summary>
    ''' Recognizes the form with barcode fields.
    ''' </summary>
    ''' <param name="formRecognitionManager">The form recognition manager.</param>
    ''' <param name="image">The image.</param>
    ''' <remarks>
    ''' The BarcodeField and BarcodeFieldTemplate classes are available
    ''' in the VintaSoft Forms Processing Demo source codes.
    ''' </remarks>
    Public Shared Sub RecognizeFormWithBarcodeFields(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
                    ' an example of BarcodeField class implementation can be found
                    ' in the VintaSoft Forms Processing Demo source codes
                    If TypeOf recognizedField Is BarcodeField Then
                        Dim barcodeField As BarcodeField = DirectCast(recognizedField, BarcodeField)
                        ' write field info
                        System.Console.WriteLine(String.Format("  Barcode field: name: {0}; type: {1}; value: {2}; confidence: {3:F1}%", barcodeField.Name, barcodeField.BarcodeInfo.BarcodeType, barcodeField.Value, barcodeField.Confidence * 100))
                    End If
                Next
            End If
        End If
    End Sub