pub struct OcrEngine { /* private fields */ }Expand description
A loaded, warm OCR engine.
Build once on a dedicated worker thread; reuse across slides. DirectML sessions are GPU-state-bound — keep on the same thread.
Implementations§
Source§impl OcrEngine
impl OcrEngine
Sourcepub fn load(model_dir: &Path) -> Result<Self, OcrError>
pub fn load(model_dir: &Path) -> Result<Self, OcrError>
Load using OcrArtifactManifest::pp_ocr_v6, the digest-pinned model set with
resolved provenance.
Sourcepub fn load_with_manifest(
model_dir: &Path,
manifest: &OcrArtifactManifest,
) -> Result<Self, OcrError>
pub fn load_with_manifest( model_dir: &Path, manifest: &OcrArtifactManifest, ) -> Result<Self, OcrError>
Load det + rec sessions from an explicit, verified model directory.
Probes DirectML first on Windows and records any CPU fallback.
Expected files:
<model_dir>/det.onnxdetector ONNX<model_dir>/rec.onnxrecognizer ONNX<model_dir>/en_dict.txtcharacter dictionary (UTF-8, one char/line)
Sourcepub fn load_with_lease(
model_dir: &Path,
manifest: &OcrArtifactManifest,
lease_hook: Option<&dyn ModelLeaseHook>,
) -> Result<Self, OcrError>
pub fn load_with_lease( model_dir: &Path, manifest: &OcrArtifactManifest, lease_hook: Option<&dyn ModelLeaseHook>, ) -> Result<Self, OcrError>
Like OcrEngine::load_with_manifest, taking a model-store lease first.
The hook is called before any artifact is verified, so an app’s model GC cannot replace the payload between verification and session construction. The returned guard is held until the engine is dropped (after its sessions).
Sourcepub fn validate_sessions(
model_dir: &Path,
manifest: &OcrArtifactManifest,
) -> Result<(), OcrError>
pub fn validate_sessions( model_dir: &Path, manifest: &OcrArtifactManifest, ) -> Result<(), OcrError>
Verify model_dir against manifest, then build and drop real det + rec sessions.
For migration and doctor checks that already hold the app’s model lease, so none is taken here. Native-only OCR callers never need this.
pub fn provider_diagnostics(&self) -> &[ProviderDiagnostic]
Sourcepub fn run(&mut self, img: &RgbImage) -> Result<String, OcrError>
pub fn run(&mut self, img: &RgbImage) -> Result<String, OcrError>
OCR a pre-loaded RGB image; returns newline-joined text.
Sourcepub fn run_lines(&mut self, img: &RgbImage) -> Result<Vec<OcrLine>, OcrError>
pub fn run_lines(&mut self, img: &RgbImage) -> Result<Vec<OcrLine>, OcrError>
OCR with per-line geometry: one OcrLine per visual line, rect =
union of the line’s detected boxes normalized to the image (top-left
origin), confidence = mean CTC character score when the recognizer
emits probabilities.