How yuta1984/ndlkotenocr-lite-web works
Project Type and Purpose
• This is a full-stack (in the sense of “frontend only”) single-page web application (SPA) that runs entirely in the browser.
• Purpose: perform OCR on classical Japanese books by detecting text regions and recognizing characters, all using ONNX models in WebAssembly.
Main Components
A. Client / Browser Environment
– HTML5/CSS/Canvas (index.html + Canvas API)
– JavaScript runtime + ONNX Runtime Web (WASM backend)
B. Application Logic (bundled by Webpack)
1. index.js (orchestrator / entry point)
2. layout-detector.js (text-region detection using RTMDet ONNX model)
3. reading-order.js (computes proper reading order for Japanese text blocks)
4. text-recognizer.js (character recognizer using Parseq NDL ONNX model)
5. output-generator.js (formats results into XML/JSON/TXT)
C. Machine-Learning Assets
– ONNX models in models/
• rtmdet-s-1280x1280.onnx
• parseq-ndl-32x384-tiny-10.onnx
D. Configuration
– YAML files in config/ for model parameters, thresholds, language specifics
E. Build & Deployment
– Webpack config + local dev server (npm start → localhost:9000)
– Static hosting (e.g., Netlify)
Data-flow & Interaction
1. User opens the page (index.html) → Webpack-bundled JS loads.
2. index.js initializes ONNX Runtime Web (WASM) and loads the two ONNX models over HTTP.
3. User supplies an image → drawn to HTML5 Canvas.
6. For each region: text-recognizer.js extracts the sub-image, runs parseq-ndl model in ONNXRuntime Web → yields recognized text.
8. Or download results.
Architectural Patterns & Principles
• Modular pipeline: each stage is an independent module with a defined input/output.
• Separation of concerns: detection, ordering, recognition, and output formatting are separate.
• Client-side inference: all ML runs in the browser (ONNX + WASM) → no server.
• Bundler-driven deployment: Webpack assembles code, assets, and models into static files.
– Clear component labels (e.g., “layout-detector.js”)
– Notes on any external dependencies (e.g., ONNX model download over HTTP)