VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.FormsProcessing.TemplateMatching Namespace / TemplateMatchingCommand Class
Members Example



In This Topic
    TemplateMatchingCommand Class
    In This Topic
    Compares an image with template images and determines the template image which is most closely matches the image.
    Object Model
    TemplateMatchingCommand ClassImageImprintGeneratorCommand ClassTemplateMatchingResult ClassProcessingCommandResults ClassProcessingCommandResult ClassImageCollection ClassVintasoftImage Class
    Syntax
    'Declaration
     
    Public Class TemplateMatchingCommand 
       Inherits Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase
    public class TemplateMatchingCommand : Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase 
    public __gc class TemplateMatchingCommand : public Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase 
    public ref class TemplateMatchingCommand : public Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase 
    Example
    This example shows how to determine a type of document (invoice or tax return) on image.
    ''' <summary>
    ''' Identifies the type of document.
    ''' </summary>
    ''' <param name="invoiceTemplateFilename">The invoice template filename.</param>
    ''' <param name="taxReturnTemplateFilename">The tax return template filename.</param>
    ''' <param name="documentFilename">The document filename.</param>
    Public Shared Sub IdentifyTypeOfDocument(invoiceTemplateFilename As String, taxReturnTemplateFilename As String, documentFilename As String)
        ' create new template matching command
        Dim templateMatchingCommand As New Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand()
        ' open invoice template
        Dim invoiceTemplateImage As New Vintasoft.Imaging.VintasoftImage(invoiceTemplateFilename)
        templateMatchingCommand.TemplateImages.Add(invoiceTemplateImage)
        ' open tax return template
        Dim taxReturnTemplateImage As New Vintasoft.Imaging.VintasoftImage(taxReturnTemplateFilename)
        templateMatchingCommand.TemplateImages.Add(taxReturnTemplateImage)
        ' open test image
        Using testImage As New Vintasoft.Imaging.VintasoftImage(documentFilename)
            ' execute template matching
            templateMatchingCommand.ExecuteInPlace(testImage)
        End Using
        ' if image is recognized
        If templateMatchingCommand.Result.ImageCompareResult.IsReliable Then
            ' write matching template type
            If templateMatchingCommand.Result.TemplateImage Is invoiceTemplateImage Then
                System.Console.WriteLine("Document is an invoice.")
            Else
                System.Console.WriteLine("Document is a tax return.")
            End If
        Else
            System.Console.WriteLine("Document type is not recognized.")
        End If
        ' dispose template images
        templateMatchingCommand.TemplateImages.ClearAndDisposeItems()
    End Sub
    /// <summary>
    /// Identifies the type of document.
    /// </summary>
    /// <param name="invoiceTemplateFilename">The invoice template filename.</param>
    /// <param name="taxReturnTemplateFilename">The tax return template filename.</param>
    /// <param name="documentFilename">The document filename.</param>
    public static void IdentifyTypeOfDocument(
        string invoiceTemplateFilename,
        string taxReturnTemplateFilename,
        string documentFilename)
    {
        // create new template matching command
        Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand templateMatchingCommand = 
            new Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand();
        // open invoice template
        Vintasoft.Imaging.VintasoftImage invoiceTemplateImage = 
            new Vintasoft.Imaging.VintasoftImage(invoiceTemplateFilename);
        templateMatchingCommand.TemplateImages.Add(invoiceTemplateImage);
        // open tax return template
        Vintasoft.Imaging.VintasoftImage taxReturnTemplateImage = 
            new Vintasoft.Imaging.VintasoftImage(taxReturnTemplateFilename);
        templateMatchingCommand.TemplateImages.Add(taxReturnTemplateImage);
        // open test image
        using (Vintasoft.Imaging.VintasoftImage testImage = 
            new Vintasoft.Imaging.VintasoftImage(documentFilename))
        {
            // execute template matching
            templateMatchingCommand.ExecuteInPlace(testImage);
        }
        // if image is recognized
        if (templateMatchingCommand.Result.ImageCompareResult.IsReliable)
        {
            // write matching template type
            if (templateMatchingCommand.Result.TemplateImage == invoiceTemplateImage)
                System.Console.WriteLine("Document is an invoice.");
            else
                System.Console.WriteLine("Document is a tax return.");
        }
        else
        {
            System.Console.WriteLine("Document type is not recognized.");
        }
        // dispose template images
        templateMatchingCommand.TemplateImages.ClearAndDisposeItems();
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase
          Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also