The Best Go API for Shipping Container OCR

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

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

The Problem with Shipping Container Parsing in Go

Extracting shipping container numbers from images presents severe technical hurdles for Go-based backend systems. Container IDs are often printed vertically, heavily rusted, or physically damaged. Terminal gate cameras capture images at skewed angles, in low light, or with heavy shadows. Attempting to use standard OCR libraries or building custom regex parsers for ISO 6346 validation is notoriously unreliable due to these real-world inconsistencies, leading to automated gate bottlenecks and high manual review costs.

The StructOCR Solution

StructOCR leverages advanced deep learning models specifically trained to overcome these port and yard challenges. Our AI automatically corrects perspective distortion, deskews images, and accurately reads vertical or degraded text. We provide an ISO 6346 compliant extraction out of the box. Returning validated, structured JSON directly to your application in under 5 seconds, it is the ideal solution for seamless integration into your logistics and port automation systems.

Common Use Cases

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

Implementation: Raw API Request

Complete, runnable Go code to extract data from a Shipping Container. Note: StructOCR efficiently handles direct file uploads via standard HTTP requests.

Prerequisite: Go 1.16+

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

package main

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	apiKey := "YOUR_API_KEY" // Replace with your actual API key
	imagePath := "./container_image.jpg" // Replace with the path to your image

	// 1. Open the image file directly (StructOCR supports direct file upload)
	file, err := os.Open(imagePath)
	if err != nil {
		fmt.Println("Error opening file:", err)
		os.Exit(1)
	}
	defer file.Close()

	// 2. Create a new HTTP request targeting the container endpoint
	req, err := http.NewRequest("POST", "https://api.structocr.com/v1/container", file)
	if err != nil {
		fmt.Println("Error creating request:", err)
		os.Exit(1)
	}

	// 3. Set the required headers for binary file upload
	req.Header.Set("x-api-key", apiKey)
	req.Header.Set("Content-Type", "application/octet-stream")

	// 4. Make the API request
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		fmt.Println("Error making API request:", err)
		os.Exit(1)
	}
	defer res.Body.Close()

	// 5. Parse the response body
	body, _ := io.ReadAll(res.Body)
	var response map[string]interface{}
	err = json.Unmarshal(body, &response)
	if err != nil {
		fmt.Println("Error decoding JSON response:", err)
		os.Exit(1)
	}

	// 6. Handle the API response
	if success, ok := response["success"].(bool); ok && success {
		if data, ok := response["data"].(map[string]interface{}); ok {
			fmt.Println("✅ Extraction Successful!\n")
			
			if containerNum, exists := data["container_number"].(string); exists {
				fmt.Println("Container Number:", containerNum)
			}
			if isValid, exists := data["is_valid"].(bool); exists {
				fmt.Println("Is Valid (ISO 6346):", isValid)
			}
			if conf, exists := data["confidence"].(string); exists {
				fmt.Println("Confidence:", conf)
			}

			// Accessing parsed components
			if parsed, exists := data["parsed"].(map[string]interface{}); exists {
				fmt.Println("\n--- Parsed Details ---")
				fmt.Printf("Owner Code: %v\n", parsed["owner_code"])
				fmt.Printf("Category: %v\n", parsed["category"])
				fmt.Printf("Serial Number: %v\n", parsed["serial_number"])
				fmt.Printf("Check Digit: %v\n", parsed["check_digit"])
			}
		} else {
			fmt.Println("Error: 'data' payload missing.")
		}
	} else {
		fmt.Println("❌ Extraction Failed.")
		if msg, ok := response["error"].(string); ok {
			fmt.Println("Error Message:", msg)
		}
	}
}

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