Direct API for High-Accuracy C# National ID Extraction
Achieve 99.8%+ accuracy and sub-second latency via a Hybrid Vision AI & MRZ Validation engine. Built for .NET.

Why National ID OCR is Difficult
Open-source OCR tools like Tesseract fail on real-world ID documents due to inherent complexities. Laminate glare, shadows, and non-uniform lighting obscure key text fields. Images captured from mobile devices introduce unpredictable skew and rotation, breaking template-based RegEx patterns. Furthermore, parsing the Machine-Readable Zone (MRZ) requires not just extraction but also checksum validation against ICAO 9303 standards. Manually implementing and maintaining these rules, along with country-specific date formats, results in a brittle, high-maintenance system with unacceptable error rates for production KYC workflows.
Enterprise-Grade Extraction with StructOCR
StructOCR replaces fragile RegEx with pre-trained Deep Learning models specifically architected for identity documents. Our id parsing api pipeline includes automatic image pre-processing, performing affine transformations to correct skew (deskewing) and applying filters to remove camera noise (denoising). Unlike Tesseract, which returns a raw dump of text coordinates, StructOCR's models identify and extract semantic fields—such as 'surname' or 'date_of_expiry'—and deliver them in a standardized, validated JSON format, facilitating robust information parsing. This eliminates post-processing logic and provides a reliable, single-step data extraction solution.
Production Use Cases
- Digital Onboarding (KYC): Reduce drop-off rates by pre-filling user data from National IDs in < 2 seconds.
- Fraud Prevention: Detect tampered fonts or mismatched MRZ checksums automatically.
- Global Compliance: Handle National IDs from 200+ jurisdictions without custom rules.
Live Demo: ID card scanner
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
Implementation: Raw C# (HttpClient)
The following C# code demonstrates a complete flow using `System.Net.Http`. It correctly handles authentication and deserializes both the Visual Zone data and the Machine-Readable Zone (MRZ).
Prerequisite: .NET Core 3.1+ or .NET 5/6/7+
// 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
// 👉 https://structocr.com/register
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
public class NationalIdOcrExample
{
private const string ApiKey = "YOUR_API_KEY_HERE";
private const string ApiEndpoint = "https://api.structocr.com/v1/national-id";
private static readonly HttpClient client = new HttpClient();
public static async Task Main(string[] args)
{
string imagePath = "id_card.jpg";
if (!File.Exists(imagePath)) return;
try
{
byte[] imageBytes = await File.ReadAllBytesAsync(imagePath);
string base64Image = Convert.ToBase64String(imageBytes);
var payload = new { img = base64Image };
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("x-api-key", ApiKey);
HttpResponseMessage response = await client.PostAsJsonAsync(ApiEndpoint, payload);
string responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode) return;
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var result = JsonSerializer.Deserialize<ApiResponse>(responseBody, options);
if (result?.Success == true && result.Data != null)
{
var data = result.Data;
Console.WriteLine($"ID Number: {data.DocumentNumber}");
Console.WriteLine($"Name: {data.GivenNames} {data.Surname}");
if (data.AdditionalFields != null && !string.IsNullOrEmpty(data.AdditionalFields.MrzLine1))
{
Console.WriteLine($"MRZ Line 1: {data.AdditionalFields.MrzLine1}");
}
}
}
catch (Exception e) { Console.WriteLine(e.Message); }
}
}
public class ApiResponse
{
public bool Success { get; set; }
public IdData Data { get; set; }
}
public class IdData
{
[JsonPropertyName("country_code")]
public string CountryCode { get; set; }
[JsonPropertyName("document_number")]
public string DocumentNumber { get; set; }
public string Surname { get; set; }
[JsonPropertyName("given_names")]
public string GivenNames { get; set; }
[JsonPropertyName("additional_fields")]
public AdditionalFieldsData AdditionalFields { get; set; }
}
public class AdditionalFieldsData
{
[JsonPropertyName("mrz_line_1")]
public string MrzLine1 { get; set; }
[JsonPropertyName("mrz_line_2")]
public string MrzLine2 { get; set; }
[JsonPropertyName("mrz_line_3")]
public string MrzLine3 { get; set; }
}Technical Specs
- •Latency: < 4s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Base64 Encoded)
- •Max File Size: 4.5MB
- •Output: JSON (Structured Data)
Key Features
- •Hybrid VIZ + MRZ AI: Cross-validates unstructured visual data against cryptographic MRZ checksums for zero hallucination.
- •Specialized Numbers: Extracts region-specific IDs like CNP (Romania), CPF (Brazil), and NIN (Nigeria).
- •Multi-line Addresses: Intelligently reconstructs full addresses from fragmented lines on ID cards.
Sample JSON Output
StructOCR returns a normalized JSON object containing both Visual Zone (VIZ) extraction and raw Machine-Readable Zone (MRZ) lines.
{
"success": true,
"data": {
"type": "national_id",
"country_code": "ROU",
"nationality": "ROMANA",
"document_number": "123456",
"card_series": "KS",
"personal_number": "1920319123456",
"surname": "POPESCU",
"given_names": "ANDREI",
"sex": "M",
"date_of_birth": "1992-03-19",
"place_of_birth": "Jud. CS Mun. Reșița",
"address": "Jud. CS Orș. Bocșa Str. Nucilor Nr. 15",
"date_of_issue": "2020-05-10",
"date_of_expiry": "2030-05-10",
"issuing_authority": "SPCLEP Bocșa",
"additional_fields": {
"phone_number": null,
"tramite_number": null,
"ejemplar": null,
"mrz_line_1": "IDROU123456<0<<<<<<<<<<<<<<<<",
"mrz_line_2": "9203195M3005108ROU19203191234562",
"mrz_line_3": null
}
}
}Frequently Asked Questions
Do you support Machine Readable Zones (MRZ) on ID cards?
Yes! Our engine natively supports ICAO 9303 standard MRZ formats (TD1/TD2) found on many global ID cards. Our Hybrid architecture extracts both the raw MRZ lines and cross-validates them against the Visual Zone (VIZ) for maximum accuracy.
How does StructOCR compare to AWS Textract or Google Vision?
Generic cloud OCR services like Textract or Vision provide raw text blocks and coordinates. They require you to build and maintain complex parsing logic to identify fields like 'Date of Birth'. StructOCR is a specialized API trained specifically for identity documents. It returns a structured JSON with pre-identified, validated fields, eliminating the need for any post-processing on your end.
Do you store the uploaded images?
No. We have a strict data privacy policy. Images are processed in-memory and are permanently deleted immediately after the OCR process completes. We do not store any customer PII.
How to handle blurry images?
Our API includes an internal image enhancement engine that automatically applies deblurring and sharpening filters to low-quality images before processing to maximize extraction accuracy.
You May Also Like
Related tutorials, platform guides, and comparisons
Indonesia KTP OCR with Node.js SDK
Extract NIK, names, dates and other visible fields from Kartu Tanda Penduduk (KTP) with the StructOCR Node.js SDK and Express.
UAE Emirates ID OCR with Node.js SDK
Extract Emirates ID number, names, dates and other visible fields from Emirates ID with the StructOCR Node.js SDK and Express.
Go National ID OCR API
Upload an image for a free test! High-accuracy National ID data extraction for Go developers. Get structured JSON output via a simple API call, replacing unreliable open-source tools.
Egypt ID OCR API & Python SDK
Python Tutorial: Automate KYC in Egypt. Extract data from National IDs using our SDK. Upload an image to test our ID OCR engine live for free.
India Aadhaar OCR with Node.js SDK
Extract Aadhaar number, names, dates and other visible fields from Aadhaar card with the StructOCR Node.js SDK and Express.
Pakistan CNIC OCR with Node.js SDK
Extract CNIC number, names, dates and other visible fields from Computerized National Identity Card (CNIC) with the StructOCR Node.js SDK and Express.
Malaysia MyKad OCR with Node.js SDK
Extract identity number, names, dates and other visible fields from MyKad with the StructOCR Node.js SDK and Express.
Côte d'Ivoire CNI (Carte Nationale d'Identité) OCR Python SDK
Python Tutorial: Automate KYC in Côte d'Ivoire. Extract French text, NNI, and validate TD1 MRZ from the ONECI CNI using StructOCR Python SDK.
Bangladesh Smart NID OCR Python SDK
Python Tutorial: Automate KYC in Bangladesh. Extract complex Bengali text and decode 2D barcodes from Smart NIDs using StructOCR Python SDK.
France Carte Nationale d'Identité OCR Python SDK
Python Tutorial: Automate KYC in France. Extract data from Carte Nationale d'Identité and validate TD1/TD2 MRZ using StructOCR Python SDK. Supports native text.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add National ID OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Bolt.new app. Build KYC and identity verification flows right in your browser.
Add National ID OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API using the Cursor AI code editor. Build KYC and identity verification flows rapidly.
Add National ID OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Lovable.dev app. Build KYC and identity verification flows with zero backend.
Add National ID OCR to Your Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Replit application. Build KYC and identity verification flows using Replit Agent and Secrets.
Add National ID OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a v0 by Vercel app. Build KYC and identity verification flows with zero backend.
Add Passport OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR Passport scanner API using the Cursor AI code editor. Build travel, hospitality, and global KYC flows rapidly.
From tutorial to production in 5 minutes.
You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.