How to use c# scan and read text in pictures

Time:2021-12-2
catalogue
  • Program test environment:
  • Detailed steps

Program test environment:

  • Visual studio version is required to be no less than 2017
  • Image scanner: spire.ocr for. Net
  • Image format: PNG (the image format here supports JPG, PNG, GIF, BMP, tiff and other formats)
  • Scanned picture text: Chinese (Chinese, English, Japanese, Korean, German, French, etc. can be supported)
  • .Net Core 2.1

Detailed steps

1. Create a. Net core console application.

2. Add dependency through nuget

(1) In solution explorer, right-click dependency and select manage nuget package

(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 two pop-up windows

(3) When finished, you can view the added dependencies

3. Copy DLL

Case 1: if it is. Net core 3.0 or above, copy the six DLL files shown in the figure from bin \ debug \ netcoreapp3.0 \ runtimes \ win-x64 \ native folder to the program running path bin \ debug \ netcoreapp3.0;

Case 2: if the version of. Net core is less than 3.0 (such as the test environment in this text), you need to download the spire.ocr package, unzip it, and path the file to spire.ocr \ spire.ocr_ Copy the 6 DLLs in dependency \ x64 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 picture:

Text reading result:

The above is how to use c# to scan and read the text in the picture. For more information about using c# to scan and read the text in the picture, please pay attention to other related articles of developeppaer!