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 host_resize;
34pub mod layout;
35pub mod model;
36pub mod preprocess;
37pub mod recognition;
38pub mod runner;
39pub mod text;
40pub mod weights;
41
42#[cfg(feature = "rlx")]
43pub mod rlx;
44
45#[cfg(feature = "rten-inference")]
46pub mod inference;
47
48pub mod cli;
49
50pub use capabilities::{STANDARD_DEVICE_NAMES, STANDARD_DEVICES, validate_device};
51pub use config::{DEFAULT_ALPHABET, DecodeMethod, DetectionParams, OcrConfig};
52pub use ctc::{CtcHypothesis, CtcStep, decode};
53pub use engine::{OcrEngine, OcrEngineParams, OcrInput, input_image, ocr_rgb_bytes};
54pub use preprocess::{BLACK_VALUE, DimOrder, ImageSource, ImageSourceError, prepare_image};
55pub use runner::{OcrOutput, OcrRunner, OcrRunnerBuilder};
56pub use text::{TextChar, TextItem, TextLine, TextWord};
57pub use weights::{
58    HF_DETECTION_RTEN, HF_DETECTION_ST, HF_DETECTION_ST_FULL, HF_RECOGNITION_RTEN,
59    HF_RECOGNITION_ST, HF_RECOGNITION_ST_FULL, SafetensorsFile, is_rten_checkpoint,
60    load_rlx_weights, load_safetensors, load_safetensors_weights, resolve_model_dir,
61};
62
63pub use model::{DetectionGraphConfig, RecognitionGraphConfig};
64#[cfg(feature = "rlx")]
65pub use rlx::{RlxTextDetector, RlxTextRecognizer};
66
67#[cfg(feature = "rten-inference")]
68pub use inference::{RtenTextDetector, RtenTextRecognizer};
69
70#[cfg(feature = "convert-rten")]
71pub use weights::{export_rten_to_safetensors, weight_map_from_rten};
72
73pub use rten_imageproc::RotatedRect;