Skip to main content

rlx_ocr/
lib.rs

1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! OCR engine for RLX — native compiled detection + recognition graphs.
17//!
18//! Load HuggingFace [`robertknight/ocrs`](https://huggingface.co/robertknight/ocrs) weights as
19//! `.safetensors` (use `rlx-ocr-convert` with feature `convert-rten` to export from legacy `.rten`).
20//!
21//! Detection + recognition run on every standard RLX backend when the matching `rlx-runtime`
22//! feature is enabled (`cpu`, `metal`, `mlx`, `cuda`, `rocm`, `gpu`, `vulkan`). Build with
23//! `all-backends` for a single binary that accepts all `--device` values.
24//!
25//! **Parity / baseline:** `parity-ocrs` (upstream ocrs + RTen) or `rten-inference` (RTen graphs only).
26
27pub mod capabilities;
28pub mod config;
29pub mod ctc;
30pub mod detection;
31pub mod engine;
32pub mod geom;
33pub mod layout;
34pub mod model;
35pub mod preprocess;
36pub mod recognition;
37pub mod runner;
38pub mod text;
39pub mod weights;
40
41#[cfg(feature = "rlx")]
42pub mod rlx;
43
44#[cfg(feature = "rten-inference")]
45pub mod inference;
46
47pub mod cli;
48
49pub use capabilities::{STANDARD_DEVICE_NAMES, STANDARD_DEVICES, validate_device};
50pub use config::{DEFAULT_ALPHABET, DecodeMethod, DetectionParams, OcrConfig};
51pub use ctc::{CtcHypothesis, CtcStep, decode};
52pub use engine::{OcrEngine, OcrEngineParams, OcrInput, input_image, ocr_rgb_bytes};
53pub use preprocess::{BLACK_VALUE, DimOrder, ImageSource, ImageSourceError, prepare_image};
54pub use runner::{OcrOutput, OcrRunner, OcrRunnerBuilder};
55pub use text::{TextChar, TextItem, TextLine, TextWord};
56pub use weights::{
57    HF_DETECTION_RTEN, HF_DETECTION_ST, HF_DETECTION_ST_FULL, HF_RECOGNITION_RTEN,
58    HF_RECOGNITION_ST, HF_RECOGNITION_ST_FULL, SafetensorsFile, is_rten_checkpoint,
59    load_rlx_weights, load_safetensors, load_safetensors_weights, resolve_model_dir,
60};
61
62pub use model::{DetectionGraphConfig, RecognitionGraphConfig};
63#[cfg(feature = "rlx")]
64pub use rlx::{RlxTextDetector, RlxTextRecognizer};
65
66#[cfg(feature = "rten-inference")]
67pub use inference::{RtenTextDetector, RtenTextRecognizer};
68
69#[cfg(feature = "convert-rten")]
70pub use weights::{export_rten_to_safetensors, weight_map_from_rten};
71
72pub use rten_imageproc::RotatedRect;