Contents

When capturing a document with a smartphone, users expect the frame to fit immediately and cleanly. This edge detection has been a gap in the browser until now — and LDED (Lightweight Document Edge Detection) closes it.

Background

Classical image processing detects document edges through contrasts and lines. This works in the lab, but not in reality: changing light, cluttered backgrounds, and perspective distortion quickly push such methods to their limits.

iOS and Android have long since brought optimized models at the operating system level — but these are generally not accessible from a web application. And the available deep learning models are too large or too computationally intensive to run in real time on a mobile browser. The usual workaround: the image is sent to a server. This means the very document that one wants to protect leaves the device — ID card, invoice, contract.

Solution

LDED is a neural network small enough to run entirely client-side. It provides not just a mask, but directly the four corner points plus a confidence value:

Architecture MobileNetV3-Small as backbone, FPN-Lite as neck, Heatmap-Head with Soft-Argmax for the coordinates — around 2.5 million parameters
Input and Output 512 × 512 px in, four corner points (x, y) plus confidence out
Deployment Trained in PyTorch 2.x, exported to ONNX, executed in the browser via ONNX Runtime Web (WebGPU or WASM)
Size Around 10 MB as FP32, under 5 MB INT8-quantized
Data Privacy Entire inference on the device — no image upload, no backend operation, no latency from server round trips

Training was conducted in a three-stage curriculum — frozen backbone, fine-tuning, then Quantization-Aware Training — on around 8,100 raw images from DocCorner, MIDV-500/2020, and the Mendeley-Corner dataset, expanded to approximately 24,300 examples via augmentation.

Result

On the validation split, LDED consistently exceeds the set target values:

Metric Value Meaning
PCK@5 93,0 % Proportion of corners that are at most 5% of the image diagonal off
PCK@10 98,2 % Same with 10% tolerance
IoU 97,4 % Overlap of the detected with the actual document area
NME 0,39 % Mean normalized distance of the corner points

The picture is more nuanced regarding speed:

Runtime Environment Inference per Image
WebGPU, Desktop Browser ~ 60 ms
WebGPU, iPhone ~ 237 ms
WASM Fallback ~ 500 ms

The project is explicitly marked as “in development,” and the WASM path remains the next optimization challenge.

Typical use cases:

  • browser-based document scanners,
  • receipt and invoice capture on mobile devices,
  • detection of ID cards and passports,
  • integration into existing web applications without an additional backend.

Why We Share This

LDED was developed as a CAS project within our team. We decided to make the code, architecture description, training guide, and a working browser demo publicly available — as a contribution to research and education, not as a finished product.

Both can be tried directly: The Browser Demo detects document corners live via camera or uploaded image — the processing remains on your device. The model, training code, and documentation are available in the Repository on GitHub.

Content-wise, this project aligns with a stance that runs through our work: Sensitive data should be processed where it is generated. With ExeoAI, we pursue the same principle at the enterprise level — sovereign, local analysis of sensitive documents instead of processing in foreign infrastructure. LDED shows that the approach also works at the other end of the chain: already at capture, in the browser, on the user’s device.

View project

More posts