Swift package · v0.1.0

KLReadingOrder

Order OCR candidates into horizontal or vertical reading lines.

A synchronous geometry engine for horizontal, vertical, automatic, and multipage reading order. It preserves caller-owned candidate identifiers and does not perform OCR.

Platforms
iOS 17+ · macOS 14+
Toolchain
Swift 6.0+
License
MIT
Dependencies
None

Functions

  • Horizontal rows and right-to-left vertical columns
  • Automatic direction inference per page
  • Adaptive median-based geometry tolerance
  • Merged bounds, mean confidence, and source IDs

Not included

It reconstructs geometry; it does not run OCR, deskew pages, reject confidence, detect language, parse tables, or interpret document meaning.

Install with SwiftPM

Package.swiftSwift
.package(url: "https://github.com/KoenLee1023/KLReadingOrder.git", from: "0.1.0")

Usage

Integration exampleSwift
let engine = ReadingOrderEngine()
let lines = engine.reconstruct(
    candidates: observations,
    preferredDirection: .unknown
)

for line in lines {
    print(line.text)
}
ReadingOrderEngine

Filters, groups, resolves direction, clusters, orders, and aggregates observations.

ReadingOrderPolicy

Names every geometric threshold and supplies default values.

ReadingOrderLine

Returns ordered IDs, merged bounds, joined text, confidence, page, and direction.

Demo apps

Reading Flow

Visualize shuffled boxes and their reconstructed lines and IDs.

Layout Comparator

Apply horizontal, vertical, and automatic modes to the same geometry.