pub struct OcrsBackend { /* private fields */ }Expand description
Pure-Rust OCR backend backed by the ocrs
engine (which uses ONNX models via rten).
§Model files
ocrs requires two pre-trained model files in .rten format:
| Model | Default env var | Default path |
|---|---|---|
| Text detection | OCRS_DETECTION_MODEL | ~/.cache/ocrs/text-detection.rten |
| Text recognition | OCRS_RECOGNITION_MODEL | ~/.cache/ocrs/text-recognition.rten |
Download links:
- https://ocrs-models.s3-accelerate.amazonaws.com/text-detection.rten
- https://ocrs-models.s3-accelerate.amazonaws.com/text-recognition.rten
§WASM compatibility
This backend is WASM-compatible. On WASM use OcrsBackend::from_bytes
since filesystem access is unavailable.
Implementations§
Source§impl OcrsBackend
impl OcrsBackend
Sourcepub fn from_bytes(
detection: &[u8],
recognition: &[u8],
) -> Result<Self, OcrError>
pub fn from_bytes( detection: &[u8], recognition: &[u8], ) -> Result<Self, OcrError>
Create from pre-loaded model bytes.
Suitable for WASM where filesystem access is unavailable.
Pass the raw .rten file bytes for each model.
Sourcepub fn from_files(
detection_path: impl AsRef<Path>,
recognition_path: impl AsRef<Path>,
) -> Result<Self, OcrError>
pub fn from_files( detection_path: impl AsRef<Path>, recognition_path: impl AsRef<Path>, ) -> Result<Self, OcrError>
Create from filesystem paths to the .rten model files.
Not available on WASM (use OcrsBackend::from_bytes instead).
Sourcepub fn try_default() -> Result<Self, OcrError>
pub fn try_default() -> Result<Self, OcrError>
Try to initialize from standard locations.
Checks OCRS_DETECTION_MODEL / OCRS_RECOGNITION_MODEL env vars first,
then falls back to ~/.cache/ocrs/{text-detection,text-recognition}.rten.
Returns Err(OcrError::NoEngine) when no models are found.
Not available on WASM (use OcrsBackend::from_bytes instead).
Trait Implementations§
Source§impl OcrBackend for OcrsBackend
Available on crate feature ocr only.
impl OcrBackend for OcrsBackend
ocr only.Auto Trait Implementations§
impl Freeze for OcrsBackend
impl !RefUnwindSafe for OcrsBackend
impl Send for OcrsBackend
impl Sync for OcrsBackend
impl Unpin for OcrsBackend
impl UnsafeUnpin for OcrsBackend
impl !UnwindSafe for OcrsBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more