1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! OCR (Optical Character Recognition) subsystem.
//!
//! This module provides OCR functionality using Tesseract as the backend.
//! It includes caching, table reconstruction, hOCR parsing, and batch processing.
//!
//! # Features
//!
//! - **Tesseract integration**: Native Tesseract backend via `xberg-tesseract`
//! - **Result caching**: Persistent cache for OCR results using file hashing
//! - **Table reconstruction**: Extract and reconstruct tables from hOCR/TSV output
//! - **hOCR to Markdown**: Convert hOCR format to clean Markdown
//! - **Batch processing**: Process multiple images efficiently
//! - **Language support**: Validate and configure Tesseract languages
//! - **PSM modes**: Support for all Tesseract Page Segmentation Modes
//!
//! # Example
//!
//! ```rust,no_run
//! use xberg::ocr::{OcrProcessor, TesseractConfig};
//!
//! # fn example() -> Result<(), xberg::ocr::error::OcrError> {
//! let processor = OcrProcessor::new(None)?;
//! let config = TesseractConfig::default();
//!
//! let image_bytes = std::fs::read("scanned.png").expect("failed to read image");
//! let result = processor.process_image(&image_bytes, &config)?;
//!
//! println!("Extracted text: {}", result.content);
//! # Ok(())
//! # }
//! ```
//!
//! # Optional Feature
//!
//! This module requires the `ocr` feature to be enabled:
//! ```toml
//! [dependencies]
//! xberg = { version = "4.0", features = ["ocr"] }
//! ```
/// Persistent file-backed cache for OCR results keyed by image hash and config.
/// Type conversions between internal OCR types and public API types.
/// OCR error types.
/// hOCR HTML output parser that extracts word bounding boxes and confidence scores.
/// Registry of Tesseract language codes and language-pack validation helpers.
/// Assembles layout-detection bounding boxes with OCR word spans for region-level extraction.
/// High-level Tesseract OCR processor with caching and table reconstruction.
/// TSV and hOCR table reconstruction utilities.
/// Runtime tessdata language pack download utilities.
/// Tessdata language-pack download and management utilities.
/// Native Tesseract backend using `xberg-tesseract` (C FFI).
/// WebAssembly Tesseract backend using `tesseract-wasm`.
/// OCR configuration and result types shared across all backends.
/// Utility functions for OCR result hashing and formatting constants.
/// Validation helpers for language codes and Tesseract version constraints.
pub use ;
pub use OcrError;
pub use LanguageRegistry;
pub use OcrProcessor;
pub use TessdataManager;
pub use TesseractBackend;
pub use TesseractWasmBackend;
pub use ;
pub use compute_hash;