Класс ImageImprintGeneratorCommand
В этом разделе
Создает отпечаток изображения.
Объектная модель
Синтаксис
Пример
Вот C#/VB.NET код, который демонстрирует, как синхронно идентифицировать и распознавать форму.
''' <summary>
''' Recognizes single image synchronously.
''' </summary>
''' <param name="templateManager">The template manager.</param>
''' <param name="image">The image.</param>
Public Shared Sub RecognizeSingleImageSync(templateManager As Vintasoft.Imaging.FormsProcessing.FormRecognition.FormTemplateManager, image As Vintasoft.Imaging.VintasoftImage)
' create template matching command
Dim templateMatchingCommand As New Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand()
' set minimal confidence
templateMatchingCommand.MinConfidence = 0.6F
' set template images
templateMatchingCommand.TemplateImages = templateManager.TemplateImages
' create recognition manager
Dim recognitionManager As New Vintasoft.Imaging.FormsProcessing.FormRecognitionManager(templateMatchingCommand, templateManager)
' create the command, which will process the image and search key zones based on lines
Dim keyLineRecognizerCommand As New Vintasoft.Imaging.FormsProcessing.TemplateMatching.KeyLineRecognizerCommand()
keyLineRecognizerCommand.ImagePreprocessing = New Vintasoft.Imaging.ImageProcessing.CompositeCommand(New Vintasoft.Imaging.ImageProcessing.Document.DespeckleCommand(), New Vintasoft.Imaging.ImageProcessing.Filters.DilateCommand())
' create and use the image imprint generator
recognitionManager.TemplateMatching.ImageImprintGenerator = New Vintasoft.Imaging.FormsProcessing.TemplateMatching.ImageImprintGeneratorCommand(keyLineRecognizerCommand)
' 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
' subscribe to ImageRecognitionError event to output recognition errors
AddHandler recognitionManager.ImageRecognitionError, AddressOf recognitionManager_ImageRecognitionError
' recognize the image
Dim recognitionResult As Vintasoft.Imaging.FormsProcessing.FormRecognitionResult = recognitionManager.Recognize(image)
' unsubscribe from ImageRecognitionError event
RemoveHandler recognitionManager.ImageRecognitionError, AddressOf recognitionManager_ImageRecognitionError
' if recognition failed with error (see ImageRecognitionError event handler output)
If recognitionResult Is Nothing Then
Return
End If
' 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
' write page info
System.Console.WriteLine(String.Format("Matching template: {0}; confidence: {1:F1}%.", recognizedPage.Name, imageCompareResult.Confidence * 100))
' 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
' write field info
System.Console.WriteLine(String.Format(" Name: {0}; value: {1}; confidence: {2:F1}%", recognizedField.Name, recognizedField.Value, recognizedField.Confidence * 100))
Next
End If
End If
End Sub
''' <summary>
''' Handles the ImageRecognitionError event of the FormRecognitionManager.
''' </summary>
Private Shared Sub recognitionManager_ImageRecognitionError(sender As Object, e As Vintasoft.Imaging.FormsProcessing.FormRecognitionErrorEventArgs)
System.Console.WriteLine(e.Exception.Message)
End Sub
/// <summary>
/// Recognizes single image synchronously.
/// </summary>
/// <param name="templateManager">The template manager.</param>
/// <param name="image">The image.</param>
public static void RecognizeSingleImageSync(
Vintasoft.Imaging.FormsProcessing.FormRecognition.FormTemplateManager templateManager,
Vintasoft.Imaging.VintasoftImage image)
{
// create template matching command
Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand templateMatchingCommand =
new Vintasoft.Imaging.FormsProcessing.TemplateMatching.TemplateMatchingCommand();
// set minimal confidence
templateMatchingCommand.MinConfidence = 0.6f;
// set template images
templateMatchingCommand.TemplateImages = templateManager.TemplateImages;
// create recognition manager
Vintasoft.Imaging.FormsProcessing.FormRecognitionManager recognitionManager =
new Vintasoft.Imaging.FormsProcessing.FormRecognitionManager(
templateMatchingCommand, templateManager);
// create the command, which will process the image and search key zones based on lines
Vintasoft.Imaging.FormsProcessing.TemplateMatching.KeyLineRecognizerCommand keyLineRecognizerCommand =
new Vintasoft.Imaging.FormsProcessing.TemplateMatching.KeyLineRecognizerCommand();
keyLineRecognizerCommand.ImagePreprocessing = new Vintasoft.Imaging.ImageProcessing.CompositeCommand(
new Vintasoft.Imaging.ImageProcessing.Document.DespeckleCommand(),
new Vintasoft.Imaging.ImageProcessing.Filters.DilateCommand());
// create and use the image imprint generator
recognitionManager.TemplateMatching.ImageImprintGenerator =
new Vintasoft.Imaging.FormsProcessing.TemplateMatching.ImageImprintGeneratorCommand(keyLineRecognizerCommand);
// 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
// subscribe to ImageRecognitionError event to output recognition errors
recognitionManager.ImageRecognitionError += recognitionManager_ImageRecognitionError;
// recognize the image
Vintasoft.Imaging.FormsProcessing.FormRecognitionResult recognitionResult = recognitionManager.Recognize(image);
// unsubscribe from ImageRecognitionError event
recognitionManager.ImageRecognitionError -= recognitionManager_ImageRecognitionError;
// if recognition failed with error (see ImageRecognitionError event handler output)
if (recognitionResult == null)
return;
// 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;
// write page info
System.Console.WriteLine(string.Format(
"Matching template: {0}; confidence: {1:F1}%.",
recognizedPage.Name,
imageCompareResult.Confidence * 100));
// 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)
{
// write field info
System.Console.WriteLine(string.Format(
" Name: {0}; value: {1}; confidence: {2:F1}%",
recognizedField.Name,
recognizedField.Value,
recognizedField.Confidence * 100));
}
}
}
}
/// <summary>
/// Handles the ImageRecognitionError event of the FormRecognitionManager.
/// </summary>
static void recognitionManager_ImageRecognitionError(
object sender,
Vintasoft.Imaging.FormsProcessing.FormRecognitionErrorEventArgs e)
{
System.Console.WriteLine(e.Exception.Message);
}
Иерархия наследования
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также