VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Ocr.Tesseract Namespace / TesseractOcr Class / SetVariable Methods / SetVariable(String,String) Method
Синтаксис Exceptions Ремарки Example Требования Смотрите также
В этом разделе
    SetVariable(String,String) Метод (TesseractOcr)
    В этом разделе
    Задает значение строковой переменной движка Tesseract OCR.
    Синтаксис
    'Declaration
    
    Public Overloads Function SetVariable( _
    ByVal name
    Имя переменной.
    As System.String, _
    ByVal value
    Значение переменной.
    As System.String _
    ) As Boolean
    public bool SetVariable(
    System.String name,
    System.String value
    )
    public: bool SetVariable(
    System.String name,
    System.String value
    )
    public:
    bool SetVariable(
    System.String name,
    System.String value
    )

    Parameters

    name
    Имя переменной.
    value
    Значение переменной.

    Return Value

    True, если значение переменной успешно установлено; в противном случае, false.
    Исключения
    ИсключениеОписание
    Выбрасывается, если движок OCR еще не инициализирован.
    Ремарки

    Метод Init(OcrEngineSettings) должен быть выполнен перед выполнением этого метода.

    Пример

    Вот C#/VB.NET код, который демонстрирует, как указать, что распознаваемый текст содержит только ограниченный набор символов, и распознать текст с изображения.

    
    ''' <summary>
    ''' Specifies that text contains only the limited set of characters and
    ''' recognizes the text in image.
    ''' </summary>
    ''' <param name="filename">The name of file, which stores images with text.</param>
    Public Shared Sub OcrImageWithDigits(filename As String)
        ' create an image collection
        Using images As New Vintasoft.Imaging.ImageCollection()
            ' add images from file to the image collection
            images.Add(filename)
    
            System.Console.WriteLine("Create Tesseract OCR engine...")
            ' create the Tesseract OCR engine
            Using tesseractOcr As New Vintasoft.Imaging.Ocr.Tesseract.TesseractOcr()
                System.Console.WriteLine("Initialize OCR engine...")
                ' init the Tesseract OCR engine
                tesseractOcr.Init(New Vintasoft.Imaging.Ocr.OcrEngineSettings(Vintasoft.Imaging.Ocr.OcrLanguage.English))
    
                ' set the "white list" of recognizing characters
                tesseractOcr.SetVariable("tessedit_char_whitelist", "01234567890")
    
                ' for each image
                For Each image As Vintasoft.Imaging.VintasoftImage In images
                    System.Console.WriteLine("Recognize the image...")
    
                    ' recognize text in image
                    Dim ocrResult As Vintasoft.Imaging.Ocr.Results.OcrPage = tesseractOcr.Recognize(image)
    
                    ' output the recognized text
    
                    System.Console.WriteLine("Page Text:")
                    System.Console.WriteLine(ocrResult.GetText())
                    System.Console.WriteLine()
                Next
    
                ' shutdown the Tesseract OCR engine
                tesseractOcr.Shutdown()
            End Using
    
            ' free images
            images.ClearAndDisposeItems()
        End Using
    End Sub
    
    
    
    /// <summary>
    /// Specifies that text contains only the limited set of characters and
    /// recognizes the text in image.
    /// </summary>
    /// <param name="filename">The name of file, which stores images with text.</param>
    public static void OcrImageWithDigits(string filename)
    {
        // create an image collection
        using (Vintasoft.Imaging.ImageCollection images = 
            new Vintasoft.Imaging.ImageCollection())
        {
            // add images from file to the image collection
            images.Add(filename);
    
            System.Console.WriteLine("Create Tesseract OCR engine...");
            // create the Tesseract OCR engine
            using (Vintasoft.Imaging.Ocr.Tesseract.TesseractOcr tesseractOcr = 
                new Vintasoft.Imaging.Ocr.Tesseract.TesseractOcr())
            {
                System.Console.WriteLine("Initialize OCR engine...");
                // init the Tesseract OCR engine
                tesseractOcr.Init(new Vintasoft.Imaging.Ocr.OcrEngineSettings(
                    Vintasoft.Imaging.Ocr.OcrLanguage.English));
    
                // set the "white list" of recognizing characters
                tesseractOcr.SetVariable(
                    "tessedit_char_whitelist", "01234567890");
    
                // for each image
                foreach (Vintasoft.Imaging.VintasoftImage image in images)
                {
                    System.Console.WriteLine("Recognize the image...");
    
                    // recognize text in image
                    Vintasoft.Imaging.Ocr.Results.OcrPage ocrResult = tesseractOcr.Recognize(image);
    
                    // output the recognized text
    
                    System.Console.WriteLine("Page Text:");
                    System.Console.WriteLine(ocrResult.GetText());
                    System.Console.WriteLine();
                }
    
                // shutdown the Tesseract OCR engine
                tesseractOcr.Shutdown();
            }
    
            // free images
            images.ClearAndDisposeItems();
        }
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также