C# scans and reads text in images (.NET Core)

This article introduces how to scan and read text in pictures through a C# program. Here we take creating a .Net Core program as an example. Below are the specific steps for reference.

Program testing environment:

Visual Studio version requirement is no less than 2017
Image scanning tool: Spire.OCR for .NET
Image format: png (the image format here supports JPG, PNG, GIF, BMP, TIFF and other formats)
Scanned image text: Chinese (can also be supported Chinese, English, Japanese, Korean, German, French, etc.)
.Net Core 2.1
detailed steps

1. Create a .Net Core console application.

2. Add dependencies through NuGet

(1) In [Solution Explorer], right-click [Dependencies] and select [Manage NuGet Packages]

(2) In the pop-up interface, select [Browse] - enter Spire.OCR in the search box and click "Install"

Select "OK" and "I Accept" in the 2 windows that pop up one after another.

(3) After completion, you can view the added dependencies

3.Copy dll

Case 1: If it is .net core 3.0 and above, copy the 6 dll files as shown in the figure from the bin\Debug\netcoreapp3.0\runtimes\win-x64\native folder to the program running path bin\Debug\ netcoreapp3.0;

Case 2: If it is a version below .net core 3.0 (such as the test environment in this text), you need to download the Spire.OCR package, decompress it, and add the 6 dlls in the file path Spire.OCR\Spire.OCR_Dependency\x64 Copy to the program running path F:\VS2017project\ReadTextFromImg_OCR\ReadTextFromImg_OCR\bin\Debug\netcoreapp2.1

4. After completing the above operations, you can refer to the following code content to read the text content on the picture.

using Spire.OCR;
using System.IO;

namespace ReadTextFromImg_OCR
{
    class Program
    {
        static void Main(string[] args)
        {
            OcrScanner scanner = new OcrScanner();
            scanner.Scan("image.png");
            File.WriteAllText("output.txt", scanner.Text.ToString());
        }
    }
}

Test pictures:

Test Results

Note: Currently, this OCR control only supports 64-bit systems!

Guess you like

Origin blog.csdn.net/qq_26695613/article/details/132844762