Direct API for C# Driver's License Data Extraction

Achieve 99.8%+ accuracy on Driver's License data extraction in under 1500ms via a single POST request.

Diagram showing the StructOCR API process: A developer sends a POST request with a base64 encoded driver's license image, the API processes it, and returns a structured JSON object with extracted fields like name, address, and document number.
Figure 1: StructOCR converts raw Driver's License images into validated JSON data.

Why Driver's License OCR is Difficult

Generic OCR tools fail on identity documents due to complex layouts, security features, and variable image quality. Key challenges include handling glare from laminates, correcting for skew and rotation from mobile captures, and accurately parsing the dense PDF417 barcode. Open-source solutions like Tesseract require extensive pre-processing and model training, while maintaining brittle RegEx patterns for each state and license version creates significant technical debt. The engineering cost of building and maintaining a high-accuracy, scalable system in-house consistently outweighs the benefits.

Enterprise-Grade Extraction with StructOCR

StructOCR utilizes pre-trained Deep Learning models, specialized exclusively for global identity documents. Our API pipeline automates image pre-processing, including deskewing, glare removal, and denoising, to maximize accuracy before data extraction even begins. For applications like drivers license ocr, this ensures high-quality input for downstream processes. Unlike Tesseract which returns unstructured text lines, StructOCR delivers a standardized, predictable JSON object with validated fields. This eliminates the need for manual parsing logic, reduces error rates to near-zero, and provides a reliable data structure for direct integration into systems, which is particularly beneficial for fleet management solutions.

Production Use Cases

  • Digital Onboarding (KYC): Reduce drop-off rates by pre-filling user data from Driver's Licenses in < 2 seconds.
  • Fraud Prevention: Detect tampered fonts or mismatched PDF417 checksums automatically.
  • Global Compliance: Handle Driver's Licenses from 200+ jurisdictions without custom rules.

Live Demo: Driver License OCR Scanner

No registration required. Upload a file to test the extraction.

1
Upload
2
Results

Drop files here or click to browse

JPG · PNG · WebP  ·  up to 500 files · max 4.5 MB each

No files selected
Need more testing? Create a free account to get 200 free credits (equals 100 Driver License scans).

Implementation: Raw API Request

The following C# code demonstrates a complete extraction flow using HttpClient. It correctly sets the required 'x-api-key' header, handles Base64 encoding, and parses the structured JSON response.

Prerequisite: .NET 6+ HttpClient and System.Text.Json

CODE EXAMPLE
// 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
// 👉 https://structocr.com/register

using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

public class StructOcrExample
{
    private static readonly HttpClient client = new HttpClient();

    public static async Task Main(string[] args)
    {
        var imagePath = "path/to/your/license.jpg";
        var endpointUrl = "https://api.structocr.com/v1/driver-license";
        var apiKey = "YOUR_API_KEY"; // Get this from your dashboard

        try
        {
            // 1. Read image file and convert to Base64
            byte[] imageBytes = await File.ReadAllBytesAsync(imagePath);
            string base64Image = Convert.ToBase64String(imageBytes);

            // 2. Prepare Request
            // Important: Add the x-api-key header
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("x-api-key", apiKey);

            var payload = new { img = base64Image };

            // 3. Send POST (PostAsJsonAsync automatically sets Content-Type: application/json)
            Console.WriteLine($"Sending request to {endpointUrl}...");
            HttpResponseMessage response = await client.PostAsJsonAsync(endpointUrl, payload);

            // 4. Handle Errors & Parse Response
            string responseBody = await response.Content.ReadAsStringAsync();
            
            if (!response.IsSuccessStatusCode)
            {
                Console.WriteLine($"API Error ({response.StatusCode}): {responseBody}");
                return;
            }

            var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
            StructOcrResponse? ocrResult = JsonSerializer.Deserialize<StructOcrResponse>(responseBody, options);

            if (ocrResult != null && ocrResult.Success && ocrResult.Data != null)
            {
                Console.WriteLine("Extraction Successful!");
                Console.WriteLine($"Document Number: {ocrResult.Data.DocumentNumber}");
                Console.WriteLine($"Name: {ocrResult.Data.GivenNames} {ocrResult.Data.Surname}");
                Console.WriteLine($"Region: {ocrResult.Data.Region} ({ocrResult.Data.CountryCode})");
                
                // Highlighting the advanced security feature extraction
                if (ocrResult.Data.ExtraDetails?.CardSecurityNumber != null)
                {
                    Console.WriteLine($"Security Code (DD): {ocrResult.Data.ExtraDetails.CardSecurityNumber}");
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine($"An unexpected error occurred: {e.Message}");
        }
    }
}

// Response Models matching the API Schema
public record StructOcrResponse(bool Success, LicenseData? Data);

public record LicenseData(
    [property: JsonPropertyName("type")] string Type,
    [property: JsonPropertyName("country_code")] string CountryCode,
    [property: JsonPropertyName("region")] string Region,
    [property: JsonPropertyName("document_number")] string DocumentNumber,
    [property: JsonPropertyName("personal_number")] string? PersonalNumber,
    [property: JsonPropertyName("surname")] string Surname,
    [property: JsonPropertyName("given_names")] string GivenNames,
    [property: JsonPropertyName("date_of_birth")] string DateOfBirth,
    [property: JsonPropertyName("date_of_expiry")] string DateOfExpiry,
    [property: JsonPropertyName("date_of_issue")] string DateOfIssue,
    [property: JsonPropertyName("sex")] string Sex,
    [property: JsonPropertyName("address")] string Address,
    [property: JsonPropertyName("vehicle_class")] string VehicleClass,
    [property: JsonPropertyName("extra_details")] ExtraDetailsData? ExtraDetails
);

public record ExtraDetailsData(
    [property: JsonPropertyName("card_security_number")] string? CardSecurityNumber,
    [property: JsonPropertyName("fathers_name")] string? FathersName,
    [property: JsonPropertyName("mothers_name")] string? MothersName,
    [property: JsonPropertyName("rg_number")] string? RgNumber
);

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

  • True Global Compatibility: Out-of-the-box support for North American AAMVA standards, EU numbered fields, and complex LATAM layouts (e.g., Brazil CNH) without maintaining custom RegEx.
  • Date Normalization: All dates automatically formatted to YYYY-MM-DD.
  • Vehicle Class Parsing: Extracts allowed vehicle categories (e.g., A, B, C).

Sample JSON Output

StructOCR returns a normalized JSON object, regardless of the input image angle or quality.

{
  "success": true,
  "data": {
    "type": "drivers_license",
    "country_code": "USA",
    "region": "CA",
    "document_number": "E3802489",
    "personal_number": null,
    "surname": "IDNOOB",
    "given_names": "MING",
    "address": "750 GONZALEZ DR APT 6B, SAN FRANCISCO, CA 94512",
    "vehicle_class": "C",
    "sex": "F",
    "date_of_birth": "1988-06-06",
    "date_of_expiry": "2020-06-06",
    "date_of_issue": "2015-07-22",
    "extra_details": {
      "card_security_number": "06/09/2014599A5/DOFD/19",
      "fathers_name": null,
      "mothers_name": null,
      "rg_number": null
    }
  }
}

Frequently Asked Questions

How does StructOCR compare to AWS Textract or Google Vision?

Generic cloud OCR services like Textract or Vision return raw lines of text, leaving your team to parse, validate, and structure the data. StructOCR is a specialized model for identity documents. It bypasses the parsing step, delivering structured, labeled fields (e.g., `date_of_birth`, `document_number`) with built-in validation, reducing development time and improving accuracy.

Do you store the uploaded images?

No. We operate on a zero-retention policy. Images are processed entirely in-memory and are purged immediately after the API call completes. We do not persist PII on our systems.

How to handle blurry images?

Our API includes an automated image enhancement pipeline. Before OCR, it performs de-skewing, noise reduction, and sharpening to maximize accuracy even on sub-optimal, low-resolution, or blurry images captured from mobile devices.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

US Driver License OCR with Python SDK

Extract structured fields from a United States state-issued driver license with the StructOCR Python SDK and FastAPI.

Python · Driver License
Tutorial

Go Driver License OCR API

Upload an image for a free test! Struggling with manual driver's license data entry? Our Go API delivers structured JSON in <5s, boasting 98.5% uptime and SOC2 compliance with AES-256 encryption.

Go · Driver License
Tutorial

Node.js Driver License Verification API

Stop manual driver license checks. Our Node.js API delivers verified data in JSON within <4s, secured by AES-256 encryption and SOC2 compliance. Achieve 98.5% uptime. Upload an image for a free test!

Node.js · Driver License
Country Tutorial

UK Driver License OCR with Python SDK

Extract structured fields from a United Kingdom photocard driving licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Tutorial

Python Driver License OCR SDK & API

Stop struggling with manual data entry. Integrate our driver license OCR SDK (Python wrapper) to extract structured JSON in <3s. Upload an image for a free test! Secure, accurate, and developer-friendly.

Python · Driver License
Country Tutorial

Canada Driver License OCR with Python SDK

Extract structured fields from a Canada provincial driver licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Brazil Driver License OCR with Python SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Brazil Driver License OCR with Node.js SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

Australia Driver License OCR with Python SDK

Extract structured fields from a Australia state or territory driver licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Australia Driver License OCR with Node.js SDK

Extract structured fields from a Australia state or territory driver licence with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

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.

Instant Access Cancel Anytime 99.9% Uptime