The Best C# API for Shipping Container OCR

Stop using regex. Extract structured data from Shipping Containers with 99% accuracy using C# and .NET.

Shipping Container OCR extraction process diagram
StructOCR transforms raw Shipping Container images into validated JSON.

The Problem with Shipping Container Parsing in .NET

Developing robust C# OCR pipelines for shipping containers using tools like Tesseract.NET is highly challenging. Enterprise logistics systems face real-world variables: container IDs printed vertically, extreme rust, physical damage, low-light terminal environments, and skewed camera angles. Relying on basic text extraction combined with complex C# regular expressions for ISO 6346 validation results in brittle applications, high error rates, and increased manual exception handling.

The StructOCR Solution

StructOCR enables your .NET applications to bypass complex computer vision configurations by utilizing our specialized deep learning API. Our service automatically handles perspective deskewing and vertical text reading, guaranteeing ISO 6346 compliant extraction. We return parsed, validated JSON directly to your C# backend, making it incredibly simple to integrate accurate container tracking into your logistics and port automation platforms.

Common Use Cases

  • Terminal Automation: Speed up gate operations and yard management by instantly capturing container numbers via .NET services.
  • Customs & Compliance: Automate cross-border document verification and manifesting within enterprise ERPs.
  • Asset Tracking: Monitor shipping container movements across the global supply chain with real-time data ingestion.

Implementation: Raw API Request

Complete, runnable C# code using HttpClient to extract data from a Shipping Container via direct file upload.

Prerequisite: .NET Core 3.1+ / .NET 6+

CODE EXAMPLE
// šŸ’° Save 30%+ vs competitors. Get 20 free credits instantly:
// šŸ‘‰ https://structocr.com/register

using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

public class ContainerOcrExample
{
    public static async Task Main(string[] args)
    {
        string apiKey = "YOUR_API_KEY"; // Replace with your actual API key
        string imagePath = "path/to/your/container_image.jpg"; // Replace with the path to your container image

        try
        {
            Console.WriteLine($"Reading image from {imagePath}...");

            // 1. Open the file stream directly for efficient upload
            using var fileStream = File.OpenRead(imagePath);
            using var streamContent = new StreamContent(fileStream);
            streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            // 2. Configure the HTTP client
            using var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Add("x-api-key", apiKey);
            httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            Console.WriteLine("Uploading to StructOCR API...");

            // 3. Send the POST request (Direct File Upload)
            HttpResponseMessage response = await httpClient.PostAsync("https://api.structocr.com/v1/container", streamContent);

            // 4. Handle the response
            if (response.IsSuccessStatusCode)
            {
                string responseBody = await response.Content.ReadAsStringAsync();

                // Parse the JSON response
                using (JsonDocument document = JsonDocument.Parse(responseBody))
                {
                    JsonElement root = document.RootElement;

                    if (root.GetProperty("success").GetBoolean())
                    {
                        JsonElement data = root.GetProperty("data");
                        Console.WriteLine("\nāœ… Extraction Successful!");
                        Console.WriteLine($"Container Number: {data.GetProperty("container_number").GetString()}");
                        Console.WriteLine($"Is Valid (ISO 6346): {data.GetProperty("is_valid").GetBoolean()}");
                        Console.WriteLine($"Confidence: {data.GetProperty("confidence").GetString()}\n");

                        if (data.TryGetProperty("parsed", out JsonElement parsed))
                        {
                            Console.WriteLine("--- Parsed Details ---");
                            Console.WriteLine($"Owner Code: {parsed.GetProperty("owner_code").GetString()}");
                            Console.WriteLine($"Category: {parsed.GetProperty("category").GetString()}");
                            Console.WriteLine($"Serial Number: {parsed.GetProperty("serial_number").GetString()}");
                            Console.WriteLine($"Check Digit: {parsed.GetProperty("check_digit").GetString()}");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"āŒ API Error: {root.GetProperty("error").GetString()}");
                    }
                }
            }
            else
            {
                Console.WriteLine($"āŒ HTTP Error: Status Code {response.StatusCode}");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Exception: {ex.Message}");
        }
    }
}

Technical Specs

  • •Latency: < 5s (Average)
  • •Uptime: 98.5% SLA
  • •Security: AES-256 Encryption & SOC2 Compliant
  • •Input: JPG, PNG, WebP (Max 4.5MB) via Direct File Upload
  • •Output: JSON (Structured Data)

Key Features

  • •Smart Crop: Auto-detects container boundaries.
  • •ISO 6346 Validation: Cross-validates owner codes and checksums automatically.
  • •Specialized Models: Trained specifically on vertical and degraded Shipping Container text.

Sample JSON Response

The API returns a clean JSON object with normalized, parsed container fields.

{
  "success": true,
  "data": {
    "container_number": "TTNU5194822",
    "is_valid": true,
    "confidence": "High",
    "parsed": {
      "owner_code": "TTN",
      "category": "U",
      "serial_number": "519482",
      "check_digit": "2"
    }
  }
}

Frequently Asked Questions

What file formats are supported?

JPG, PNG, and WebP images up to 4.5MB.

Is data stored?

No. Images are processed in-memory and deleted immediately.

How to handle errors?

Check the 'success' flag and 'error' message in the response.

More OCR Tutorials

Precise Data Extraction and Seamless Integration with AI-powered OCR API.

Empower your solutions with automated data extraction by integrating best-in class StructOCR via API seamlessly.

No credit card required • Full API access included