C#: Extract Text from Images using the New Model of Spire.OCR for .NET

2024-07-18 01:09:12 Written by  support iceblue
Rate this item
(0 votes)

As of version 1.9.8, Spire.OCR for .NET offers developers a new model to extract text from images. In this article, we will demonstrate how to extract text from images in C# using the new model of Spire.OCR for .NET.

The detailed steps are as follows.

Step 1: Create a Console App (.NET Framework) in Visual Studio.

C#: Extract Text from Images using the New Model of Spire.OCR for .NET

C#: Extract Text from Images using the New Model of Spire.OCR for .NET

Step 2: Change the platform target of the application to x64.

In the application's Solution Explorer, right-click on the project's name and then select "Properties".

C#: Extract Text from Images using the New Model of Spire.OCR for .NET

Change the platform target of the application to x64. This step must be performed since Spire.OCR only supports 64-bit platforms.

C#: Extract Text from Images using the New Model of Spire.OCR for .NET

Step 3: Install Spire.OCR for .NET in your application.

Install Spire.OCR for .NET through NuGet by executing the following command in the NuGet Package Manager Console:

Install-Package Spire.OCR

C#: Extract Text from Images using the New Model of Spire.OCR for .NET

Step 4: Download the new model and dependencies of Spire.OCR for .NET.

Download the new model and dependencies of Spire.OCR for .NET (Model&Lib.zip) through the following link. Then extract the package and save it to a specific directory (such as "D:\") in your computer.

https://www.e-iceblue.com/resource/ocr_net/Model&Lib.zip

C#: Extract Text from Images using the New Model of Spire.OCR for .NET

Step 5: Use Spire.OCR for .NET to extract text from images in C#.

The following code example shows how to extract text from an image using C# and Spire.OCR for .NET:

  • C#
using Spire.OCR;
using System.IO;

namespace NewOCRModel
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Set license key
            // Spire.OCR.License.LicenseProvider.SetLicenseKey("your-license-key");
            // Create an instance of the OcrScanner class
            OcrScanner scanner = new OcrScanner();

            // Create an instance of the ConfigureOptions class to set up the scanner configuration
            ConfigureOptions configureOptions = new ConfigureOptions();

            // Set the path to the new model
            configureOptions.ModelPath = @"D:\Model&Lib\Model";

            // Set the path to the dependency libs
            configureOptions.LibPath = @"D:\Model&Lib\Lib\X64";

            // Specify the language for text recognition (such as English, Chinese, Chinesetraditional, French, German, Japanese, or Korean)
            configureOptions.Language = "English";

            // Apply the configuration options to the scanner
            scanner.ConfigureDependencies(configureOptions);

            // Extract text from an image
            scanner.Scan("test.png");

            //Save the extracted text to a text file
            string text = scanner.Text.ToString();
            File.WriteAllText("Output.txt", text);
        }
    }
}

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Thursday, 18 July 2024 01:20