Expand description
MonOcr - Mon language OCR library using ONNX models
This library provides OCR (Optical Character Recognition) functionality for Mon text using deep learning models. It supports reading text from images and PDFs, with optional accuracy measurement against ground truth text.
§The model
Weights are downloaded from janakhpon/monocr,
pinned to revision model_manager::MODEL_REVISION. That artifact takes a
[1, 1, 160, 1024] input and emits [1, sequence, 277] logits: 276
characters plus the CTC blank. The width is static: v3.5 accepts 1024 and
nothing else, where v2 accepted any width.
The charset, the input height and the classifier width are one contract. If
they drift apart the model still runs and still returns text — it is just the
wrong text, with no error anywhere. So the graph is read on load and a
disagreement yields ModelContractError instead of a result.
§Quick Start
use monocr_onnx::read_image;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = read_image("path/to/image.png").await?;
println!("Recognized text: {}", text);
Ok(())
}§Features
- Read text from single images (PNG, JPG, etc.)
- Read text from multiple images in batch
- Read text from PDF files (requires poppler-utils)
- Measure OCR accuracy against ground truth
- Customizable model paths and character sets
- Line segmentation for full page OCR
- Lines too wide for the 1024px model window are tiled at whitespace columns
rather than squeezed into it; see
MonOcr::predict_pagefor the measured reason
Re-exports§
pub use model_manager::ModelManager;pub use segmenter::cut_column;pub use segmenter::tile_line;pub use segmenter::CUT_INK_THRESHOLD;pub use segmenter::CUT_SEARCH_FRACTION;pub use segmenter::DEFAULT_DENSITY_THRESHOLD_RATIO;
Modules§
- model_
manager - Model Manager
- segmenter
- Line Segmentation
Structs§
- BBox
- Bounding box for a line or text region
- Line
Result - Result from line prediction
- Model
Contract Error - A model artifact that disagrees with the charset or the input geometry this binding was built for.
- MonOcr
- Main OCR engine for text recognition
- MonOcr
Builder - Builder for configuring and creating MonOcr instances
- OcrResult
- OCR result containing recognized text and accuracy measurement
Constants§
- DEFAULT_
INPUT_ WIDTH - Padded canvas width fed to the model.
- EXPECTED_
INPUT_ HEIGHT - Input height this binding preprocesses for.
Functions§
- calculate_
accuracy - Calculate character error rate (CER) between predicted and ground truth Returns accuracy percentage (0-100)
- normalize_
charset - Strip line terminators, and nothing else.
- normalize_
polarity - Return
imageas dark-text-on-light, inverting it when the background is dark. - page_
text - Join one page’s line texts the way
MonOcr::read_imagedoes. - read_
image - Read text from a single image file
- read_
image_ with_ accuracy - Read text from an image with accuracy measurement
- read_
images - Read text from multiple image files
- read_
pdf - Read text from a PDF file