Detect and Extract ID Card Information - C# .NET Core

This tutorial shows how to detect and extract ID card information from a given image in a C# .NET Core application using the LEADTOOLS SDK.

Overview  
Summary This tutorial covers how to find and extract ID Card features from an image in a C# .NET Core Console application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (1 KB)
Platform C# .NET Core Console Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS

Required Knowledge

Get familiar with the basic steps of creating a project and loading an image by reviewing the Add References and Set a License and Load and Save Images tutorials, before working on the Detect and Extract ID Card Information - C# .NET Core tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Load and Save Images tutorial. If you do not have that project, follow the steps in that tutorial to create it.

The references needed depend upon the purpose of the project. References can be added via NuGet packages.

This tutorial requires the following NuGet packages:

For a complete list of which DLL files are required for your application, refer to Files to be Included With Your Application.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:

Note

Adding LEADTOOLS NuGet references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Add the ID Frame Reader and Processing Code

With the project created, the references added, the license set, and the load image code added, coding can begin. The image save code is not necessary for this tutorial, so that code can be commented out or deleted.

In the Solution Explorer, open Program.cs. Add the following statements to the using block at the top of Program.cs.

C#
using System; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.Commands; 
using Leadtools.Ocr; 

Add a new method to the Program class named ReadIDCard(RasterImage image), load the sample image with RasterCodecs and pass the RasterImage class to the method.

For the purposes of this tutorial the following image is used: <INSTALL_DIR>\LEADTOOLS22\Resources\Images\License_SAMPLE.PNG

C#
static void Main(string[] args) 
{ 
    if (!SetLicense()) 
        Console.WriteLine("Error setting license"); 
    else 
        Console.WriteLine("License file set successfully"); 
 
    using (RasterCodecs codecs = new RasterCodecs()) 
    { 
        RasterImage image = codecs.Load(@"<INSTALL_DIR>\LEADTOOLS22\Resources\Images\License_SAMPLE.PNG"); 
        ReadIDCard(image); 
    } 
} 

Add the code below to the ReadIDCard() method to process the given image and output the ID values if detected.

C#
static void ReadIDCard(RasterImage image) 
{ 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      var buffer = Path.Combine(@"<INSTALL_DIR>\LEADTOOLS22\Bin\Common\OcrLEADRuntime", "LEAD.Binarize.bin"); 
      ocrEngine.Startup(null, null, null, null); 
      using (IDFrameReader idFrameReader = new IDFrameReader(File.ReadAllBytes(buffer), ocrEngine)) 
      { 
         var results = idFrameReader.Process(image); 
         if (results.Ready) 
            foreach (var res in idFrameReader.Results) 
               Console.WriteLine($"{res.Key} : {res.Value}"); 
         else 
            Console.WriteLine("No ID found in this image"); 
      } 
   } 
} 

Run the Project

Run the project by pressing F5, or by selecting Debug -> Start Debugging.

If the steps were followed correctly, the console appears and the application detects the ID information and displays it to the console.

Extracted license information displayed to the console.

Wrap-Up

This tutorial showed how to load an image and run license recognition using the IDFrameReader class.

See Also

Help Version 22.0.2021.11.30
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.