Back to Portfolio

Stack Inspection: Assessing Carton Stacking Quality from a Single Photo with Computer Vision

An AI system that assesses how cartons are stacked in trucks and containers from a single photo. It detects cartons with YOLOX, reads SKU labels with OCR, rebuilds the stack as a grid, and scores it against loading rules. It's built on ASP.NET Core and uses a detection model I trained myself.

September 29, 2026
0 views
 1
 2
 3

An AI system that assesses how cartons are stacked in trucks and containers from a single photo. It detects cartons with YOLOX, reads SKU labels with OCR, rebuilds the stack as a grid, and scores it against loading rules. It's built on ASP.NET Core and uses a detection model I trained myself.

The Problem Carton loads in trucks and containers were checked manually from field photos, which was slow and inconsistent. The photos themselves are hard to work with: they're heavily compressed, contain 100–200 small cartons of mixed sizes, are often wrapped in plastic, and frequently carry GPS camera stamps.

The Solution I designed and built two connected applications:

  1. Carton Trainer (Python): a training app for a YOLOX carton detection model. I chose YOLOX for its Apache-2.0 license, which avoids AGPL restrictions in a closed internal system. It has a device-agnostic training loop (CUDA, Apple MPS or CPU), a Gradio GUI and a model registry. Models are exported to ONNX with a model card that records metrics and recommended thresholds.
  2. Stack Inspection API (.NET 8): an inference service that processes each photo in two steps:
    • Collect SKU: the photo first goes through quality gates (minimum resolution, rejection of photos that can't be inspected or carry camera stamps). Front-layer cartons are then detected with YOLOX ONNX, SKU labels are read with PaddleOCR PP-OCRv5, and the results are arranged into a row × column grid.
    • Analyze: the grid is checked against business rules: unknown SKU, label not visible, stack height over the per-SKU limit, and weight class order (heavy class C at the bottom, light class A on top). The output is a list of violations and a score.

Key Technical Challenges

  • Front-layer filtering: perspective makes cartons from back layers visible in the photo. I built heuristics based on relative width, gaps and height so only the front layer gets scored.
  • OCR correction: SKU reads are fuzzy-matched against the master SKU list. When no master list is supplied, the system falls back to correcting reads toward the majority SKU in the same photo. Every correction is flagged with a warning so it stays transparent.
  • YOLOX postprocessing in C#: I reimplemented letterboxing, output decoding and NMS in C# and checked them against reference values from the Python trainer.
  • Cross-platform deployment: one codebase targets both Linux (Docker/Coolify) and Windows Server + IIS. Native libraries are picked per runtime identifier, and models live outside the image so they can be swapped without a rebuild.
  • Model selection per request: an endpoint lists the available models with their metrics, and Swagger offers a model dropdown.

Quality & Architecture The API follows Clean Architecture (Domain, Application, Infrastructure, Api). It has 60+ xUnit unit and integration tests that use a fixture-based fake vision layer, so they run without the model or native libraries. The build allows zero warnings (TreatWarningsAsErrors). Errors follow the ProblemDetails format (RFC 7807), Swagger includes response examples, and TypeScript contracts match the C# DTOs for frontend use.

My Role I owned the project end to end: gathering requirements and business rules, research on real field photos, model training, API architecture, implementation, testing and deployment strategy.

Tech Stack

AreaTechnologies
Backend APIC#, .NET 8, ASP.NET Core Web API, Clean Architecture
Computer VisionYOLOX, ONNX Runtime, OpenCvSharp (OpenCV), PaddleOCR PP-OCRv5 (Sdcb.PaddleOCR)
Machine Learning / TrainingPython 3.11, PyTorch, torchvision, ONNX, onnxsim, NumPy, OpenCV
Trainer ToolingGradio (GUI), Typer (CLI), Pydantic
API DocumentationSwagger / OpenAPI (Swashbuckle), ProblemDetails
TestingxUnit, WebApplicationFactory (integration tests), pytest
Frontend ContractTypeScript type definitions
DeploymentDocker, Coolify (Linux), Windows Server + IIS

🛠️Technologies Used

C#.NetASP.NetYoloXONNXOpenCVSharpPaddleOCRPytonPyTorchTouchVisionGradioPydenticSwaggerTypeScript

Project Links

Project Details

Created:September 29, 2026
Views:0
0

About the Developer

Nandang Hermawan

Nandang Hermawan

Senior Fullstack Developer

Full Stack Developer with over 9 years of experience leading technical projects from concept to deployment. Skilled in both backend and frontend development, I enjoy collaborating with cross-functional teams to deliver solutions that drive real business value.