The Best Java API for Shipping Container OCR

Stop using regex. Extract structured data from Shipping Containers with 99% accuracy using Java.

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

The Problem with Shipping Container Parsing in Java

Enterprise Java applications in logistics often struggle with legacy OCR libraries like Tesseract or JavaCV wrappers. These traditional tools fail when processing shipping containers due to heavy rust, physical damage, vertical text orientations, and skewed angles from terminal gate cameras. Attempting to build custom regex parsers for ISO 6346 standards on top of poor OCR results leads to brittle codebases and high manual intervention rates.

The StructOCR Solution

StructOCR allows your Java backend to offload complex image processing to our specialized deep learning models. Our API handles deskewing, vertical text reading, and automatically performs ISO 6346 compliant extraction. By returning validated JSON directly to your Java application, you can seamlessly integrate high-accuracy container data into your logistics and port automation systems without maintaining heavy machine learning dependencies.

Common Use Cases

  • Terminal Automation: Speed up gate operations and yard management by instantly capturing container numbers.
  • 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.

Implementation: Raw API Request

Complete, runnable Java 11+ code to directly upload an image and extract data from a Shipping Container.

Prerequisite: JDK 11+ and Gson library

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

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Path;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class ContainerOcr {

    public static void main(String[] args) throws IOException, InterruptedException {
        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 image

        // 1. Create the HTTP client
        HttpClient client = HttpClient.newHttpClient();

        // 2. Build the HTTP request (Direct File Upload)
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.structocr.com/v1/container"))
                .header("x-api-key", apiKey)
                .header("Content-Type", "application/octet-stream")
                .POST(HttpRequest.BodyPublishers.ofFile(Path.of(imagePath)))
                .build();

        System.out.println("Uploading image to StructOCR API...");

        // 3. Send the request and receive the response
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        // 4. Parse the JSON response
        Gson gson = new Gson();
        JsonObject jsonResponse = gson.fromJson(response.body(), JsonObject.class);

        // 5. Extract the Container data
        if (jsonResponse.has("success") && jsonResponse.get("success").getAsBoolean()) {
            JsonObject data = jsonResponse.getAsJsonObject("data");
            String containerNumber = data.get("container_number").getAsString();
            boolean isValid = data.get("is_valid").getAsBoolean();
            
            System.out.println("✅ Extraction Successful!");
            System.out.println("Container Number: " + containerNumber);
            System.out.println("Is Valid (ISO 6346): " + isValid);
            System.out.println("Confidence: " + data.get("confidence").getAsString());

            if (data.has("parsed")) {
                JsonObject parsed = data.getAsJsonObject("parsed");
                System.out.println("--- Parsed Details ---");
                System.out.println("Owner Code: " + parsed.get("owner_code").getAsString());
                System.out.println("Category: " + parsed.get("category").getAsString());
                System.out.println("Serial Number: " + parsed.get("serial_number").getAsString());
                System.out.println("Check Digit: " + parsed.get("check_digit").getAsString());
            }
        } else {
            String errorMsg = jsonResponse.has("error") ? jsonResponse.get("error").getAsString() : "Unknown Error";
            System.out.println("❌ Error: " + errorMsg);
        }
    }
}

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