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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! # Rust PaddleOCR
//!
//! A high-performance OCR library based on PaddleOCR models, using the MNN inference framework.
//!
//! ## Version 2.0 New Features
//!
//! - **New API Design**: Complete layered API from low-level models to high-level pipeline
//! - **Flexible Model Loading**: Support loading models from file paths or memory bytes
//! - **Configurable Detection Parameters**: Support custom detection thresholds, resolution, etc.
//! - **GPU Acceleration**: Support multiple GPU backends including Metal, OpenCL, Vulkan
//! - **Batch Processing**: Support batch text recognition for improved throughput
//!
//! ## Quick Start
//!
//! ### Simple Usage - Using High-Level API (Recommended)
//!
//! ```ignore
//! use ocr_rs::{OcrEngine, OcrEngineConfig};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create OCR engine
//! let engine = OcrEngine::new(
//! "models/det_model.mnn",
//! "models/rec_model.mnn",
//! "models/ppocr_keys.txt",
//! None, // Use default config
//! )?;
//!
//! // Open and recognize image
//! let image = image::open("test.jpg")?;
//! let results = engine.recognize(&image)?;
//!
//! for result in results {
//! println!("Text: {}, Confidence: {:.2}%", result.text, result.confidence * 100.0);
//! println!("Position: ({}, {})", result.bbox.rect.left(), result.bbox.rect.top());
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Advanced Usage - Using Low-Level API
//!
//! ```ignore
//! use ocr_rs::{DetModel, RecModel, DetOptions, DetPrecisionMode};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create detection model
//! let det = DetModel::from_file("models/det_model.mnn", None)?
//! .with_options(DetOptions::fast());
//!
//! // Create recognition model
//! let rec = RecModel::from_file("models/rec_model.mnn", "models/ppocr_keys.txt", None)?;
//!
//! // Load image
//! let image = image::open("test.jpg")?;
//!
//! // Detect and crop text regions
//! let detections = det.detect_and_crop(&image)?;
//!
//! // Recognize each text region
//! for (cropped_img, bbox) in detections {
//! let result = rec.recognize(&cropped_img)?;
//! println!("Position: ({}, {}), Text: {}",
//! bbox.rect.left(), bbox.rect.top(), result.text);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### GPU Acceleration
//!
//! ```ignore
//! use ocr_rs::{OcrEngine, OcrEngineConfig, Backend};
//!
//! let config = OcrEngineConfig::new()
//! .with_backend(Backend::Metal); // macOS/iOS
//! // .with_backend(Backend::OpenCL); // Cross-platform
//!
//! let engine = OcrEngine::new(det_path, rec_path, charset_path, Some(config))?;
//! ```
//!
//! ## Module Structure
//!
//! - [`mnn`]: MNN inference engine wrapper, provides low-level inference capabilities
//! - [`det`]: Text detection module ([`DetModel`]), detects text regions in images
//! - [`rec`]: Text recognition module ([`RecModel`]), recognizes text content
//! - [`engine`]: High-level OCR pipeline ([`OcrEngine`]), all-in-one OCR solution
//! - [`preprocess`]: Image preprocessing utilities, including normalization, scaling, etc.
//! - [`postprocess`]: Post-processing utilities, including NMS, box merging, sorting, etc.
//! - [`error`]: Error types [`OcrError`]
//!
//! ## API Hierarchy
//!
//! ```text
//! ┌─────────────────────────────────────────┐
//! │ OcrEngine (High-Level API) │
//! │ Complete detection and recognition │
//! ├─────────────────────────────────────────┤
//! │ DetModel │ RecModel │
//! │ Detection Model │ Recognition Model │
//! ├─────────────────────────────────────────┤
//! │ InferenceEngine (MNN) │
//! │ Low-level inference engine │
//! └─────────────────────────────────────────┘
//! ```
//!
//! ## Supported Models
//!
//! - **PP-OCRv4**: Stable version, good compatibility
//! - **PP-OCRv5**: Recommended version, supports multiple languages, higher accuracy
//! - **PP-OCRv5 FP16**: Efficient version, faster inference, lower memory usage
// Core modules
// Re-export commonly used types
pub use ;
pub use ;
pub use ;
pub use ;
pub use TextBox;
pub use ;
pub use ;
/// Get library version
/// Get MNN version