pub struct OcrEngine { /* private fields */ }Expand description
OCR engine
Encapsulates complete OCR pipeline, including text detection and recognition
§Example
use ocr_rs::{OcrEngine, OcrEngineConfig};
// Create engine
let engine = OcrEngine::new(
"det_model.mnn",
"rec_model.mnn",
"ppocr_keys.txt",
None,
)?;
// Recognize image
let image = image::open("test.jpg")?;
let results = engine.recognize(&image)?;
for result in results {
println!("{}: {:.2}", result.text, result.confidence);
}Implementations§
Source§impl OcrEngine
impl OcrEngine
Sourcepub fn new(
det_model_path: impl AsRef<Path>,
rec_model_path: impl AsRef<Path>,
charset_path: impl AsRef<Path>,
config: Option<OcrEngineConfig>,
) -> OcrResult<Self>
pub fn new( det_model_path: impl AsRef<Path>, rec_model_path: impl AsRef<Path>, charset_path: impl AsRef<Path>, config: Option<OcrEngineConfig>, ) -> OcrResult<Self>
Create OCR engine from model files
§Parameters
det_model_path: Detection model file pathrec_model_path: Recognition model file pathcharset_path: Charset file pathconfig: Optional engine configuration
Sourcepub fn new_with_ori(
det_model_path: impl AsRef<Path>,
rec_model_path: impl AsRef<Path>,
charset_path: impl AsRef<Path>,
ori_model_path: impl AsRef<Path>,
config: Option<OcrEngineConfig>,
) -> OcrResult<Self>
pub fn new_with_ori( det_model_path: impl AsRef<Path>, rec_model_path: impl AsRef<Path>, charset_path: impl AsRef<Path>, ori_model_path: impl AsRef<Path>, config: Option<OcrEngineConfig>, ) -> OcrResult<Self>
Create OCR engine from model files with orientation model
Sourcepub fn from_bytes(
det_model_bytes: &[u8],
rec_model_bytes: &[u8],
charset_bytes: &[u8],
config: Option<OcrEngineConfig>,
) -> OcrResult<Self>
pub fn from_bytes( det_model_bytes: &[u8], rec_model_bytes: &[u8], charset_bytes: &[u8], config: Option<OcrEngineConfig>, ) -> OcrResult<Self>
Create OCR engine from model bytes
Sourcepub fn from_bytes_with_ori(
det_model_bytes: &[u8],
rec_model_bytes: &[u8],
charset_bytes: &[u8],
ori_model_bytes: &[u8],
config: Option<OcrEngineConfig>,
) -> OcrResult<Self>
pub fn from_bytes_with_ori( det_model_bytes: &[u8], rec_model_bytes: &[u8], charset_bytes: &[u8], ori_model_bytes: &[u8], config: Option<OcrEngineConfig>, ) -> OcrResult<Self>
Create OCR engine from model bytes with orientation model
Sourcepub fn det_only(
det_model_path: impl AsRef<Path>,
config: Option<OcrEngineConfig>,
) -> OcrResult<DetOnlyEngine>
pub fn det_only( det_model_path: impl AsRef<Path>, config: Option<OcrEngineConfig>, ) -> OcrResult<DetOnlyEngine>
Create detection-only engine
Sourcepub fn rec_only(
rec_model_path: impl AsRef<Path>,
charset_path: impl AsRef<Path>,
config: Option<OcrEngineConfig>,
) -> OcrResult<RecOnlyEngine>
pub fn rec_only( rec_model_path: impl AsRef<Path>, charset_path: impl AsRef<Path>, config: Option<OcrEngineConfig>, ) -> OcrResult<RecOnlyEngine>
Create recognition-only engine
Sourcepub fn recognize(&self, image: &DynamicImage) -> OcrResult<Vec<OcrResult_>>
pub fn recognize(&self, image: &DynamicImage) -> OcrResult<Vec<OcrResult_>>
Sourcepub fn recognize_with_options(
&self,
image: &DynamicImage,
options: &RecognizeOptions,
) -> OcrResult<Vec<OcrResult_>>
pub fn recognize_with_options( &self, image: &DynamicImage, options: &RecognizeOptions, ) -> OcrResult<Vec<OcrResult_>>
Perform OCR recognition with per-call options.
RotatedTextMode::Disabled is the default and runs the same one-pass
pipeline as Self::recognize. RotatedTextMode::Robust performs two
additional detection passes and only recognizes horizontal candidates
from those rotated images, keeping the added recognition work small.
Sourcepub fn recognize_text(
&self,
image: &DynamicImage,
) -> OcrResult<RecognitionResult>
pub fn recognize_text( &self, image: &DynamicImage, ) -> OcrResult<RecognitionResult>
Perform recognition only (requires pre-cropped text line images)
Sourcepub fn recognize_batch(
&self,
images: &[DynamicImage],
) -> OcrResult<Vec<RecognitionResult>>
pub fn recognize_batch( &self, images: &[DynamicImage], ) -> OcrResult<Vec<RecognitionResult>>
Batch recognize text line images
Sourcepub fn config(&self) -> &OcrEngineConfig
pub fn config(&self) -> &OcrEngineConfig
Get configuration
Auto Trait Implementations§
impl Freeze for OcrEngine
impl RefUnwindSafe for OcrEngine
impl Send for OcrEngine
impl Sync for OcrEngine
impl Unpin for OcrEngine
impl UnsafeUnpin for OcrEngine
impl UnwindSafe for OcrEngine
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.