IdentityDocument.Processing 1.2.0

dotnet add package IdentityDocument.Processing --version 1.2.0
                    
NuGet\Install-Package IdentityDocument.Processing -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IdentityDocument.Processing" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IdentityDocument.Processing" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="IdentityDocument.Processing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IdentityDocument.Processing --version 1.2.0
                    
#r "nuget: IdentityDocument.Processing, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IdentityDocument.Processing@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IdentityDocument.Processing&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=IdentityDocument.Processing&version=1.2.0
                    
Install as a Cake Tool

IdentityDocument.Processing

IdentityDocument.Processing is a .NET library that combines Azure Computer Vision and ML.NET to process images of identity documents (ID cards, passports, licenses, etc.).
It extracts raw text from images and maps it into structured fields such as First Name, Last Name, Document Number, Dates, and more.


Features

  • OCR extraction using Azure Computer Vision.
  • Field classification and parsing with ML.NET.
  • Easy integration into ASP.NET Core and .NET 7+ applications.
  • Provides strongly-typed results for identity documents.

Installation

dotnet add package IdentityDocument.Processing

Quick Start

1. Register services in Program.cs

using IdentityDocument.Processing.Abstractions;
using IdentityDocument.Processing.Services;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
using ocr_project.Services.ComputerVisionAzure;
using OpenAI.Chat;

var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;

// Azure Computer Vision
builder.Services.AddSingleton(provider =>
{
    return new ComputerVisionClient(
        new ApiKeyServiceClientCredentials(configuration["AzureVision:Key"]))
    {
        Endpoint = configuration["AzureVision:Endpoint"]
    };
});

// OpenAI Chat client
builder.Services.AddSingleton<ChatClient>(sp =>
{
    var apiKey = configuration["OpenAI:ApiKey"];
    if (string.IsNullOrWhiteSpace(apiKey))
        throw new InvalidOperationException("OpenAI:ApiKey is missing.");

    var model = configuration["OpenAI:Model"] ?? "gpt-4o-mini";
    return new ChatClient(model, apiKey);
});

// Register services
builder.Services.AddScoped<IOpenIAService, OpenIAService>();
builder.Services.AddScoped<IComputerVisionAzureServices, ComputerVisionAzureServices>();
builder.Services.AddScoped<IIdentityDocumentServices, IdentityDocumentService>();

var app = builder.Build();
app.Run();

2. Example service usage

using IdentityDocument.Processing.Abstractions;
using Microsoft.AspNetCore.Http;

namespace MyApp.Services
{
    public class DocumentProcessingService : IDocumentProcessingServices
    {
        private readonly IIdentityDocumentServices _identityDocService;

        public DocumentProcessingService(IIdentityDocumentServices identityDocService)
        {
            _identityDocService = identityDocService;
        }

        public async Task<FileUploadResponse> IdentityDocumentProcessingImgs(ICollection<IFormFile> files)
        {
            if (files == null || files.Count == 0)
                throw new ArgumentException("At least one image must be provided.");

            var result = await _identityDocService.IdentityDocumentProsessingImgs(files);

            if (result == null)
                throw new InvalidOperationException("Document could not be processed.");

            return new FileUploadResponse
            {
                FirstNames = result.FirstNames,
                LastNames = result.LastNames,
                Country = result.Country,
                DocumentNumber = result.DocumentNumber,
                BirthDate = ParseDate(result.BirthDate),
                IssueDate = ParseDate(result.IssueDate),
                ExpiryDate = ParseDate(result.ExpiryDate),
                Sex = result.Sex,
                Nationality = result.Nationality
            };
        }

        private DateTime? ParseDate(string? value, string format = "yyyy-MM-dd")
        {
            if (string.IsNullOrWhiteSpace(value)) return null;
            if (DateTime.TryParseExact(value, format,
                System.Globalization.CultureInfo.InvariantCulture,
                System.Globalization.DateTimeStyles.None,
                out var date))
                return date;
            return null;
        }
    }
}

Requirements

  • .NET 7.0
  • Azure Computer Vision subscription (endpoint and key)
  • OpenAI API key

Configuration

{
  "AzureVision": {
    "Endpoint": "https://<your-cv-endpoint>.cognitiveservices.azure.com/",
    "Key": "YOUR_AZURE_CV_KEY"
  },
  "OpenAI": {
    "ApiKey": "YOUR_OPENAI_API_KEY",
    "Model": "gpt-4o-mini"
  }
}

Contributing

Contributions are welcome:

  1. Fork the repository.
  2. Create a feature/bugfix branch.
  3. Submit a Pull Request.

Issues


License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 128 9/8/2025
1.1.3 143 9/3/2025
1.1.1 139 9/3/2025
1.1.0 125 9/3/2025
1.0.2 175 8/28/2025
1.0.1 152 8/25/2025