Struct ocrs::OcrEngine

source ·
pub struct OcrEngine { /* private fields */ }
Expand description

Detects and recognizes text in images.

OcrEngine uses machine learning models to detect text, analyze layout and recognize text in an image.

Implementations§

source§

impl OcrEngine

source

pub fn new(params: OcrEngineParams) -> Result<OcrEngine, Box<dyn Error>>

Construct a new engine from a given configuration.

source

pub fn prepare_input( &self, image: NdTensorView<'_, f32, 3> ) -> Result<OcrInput, Box<dyn Error>>

Preprocess an image for use with other methods of the engine.

The input image should be a CHW tensor with values in the range 0-1 and either 1 (grey), 3 (RGB) or 4 (RGBA) channels.

source

pub fn detect_words( &self, input: &OcrInput ) -> Result<Vec<RotatedRect>, Box<dyn Error>>

Detect text words in an image.

Returns an unordered list of the oriented bounding rectangles of each word found.

source

pub fn find_text_lines( &self, _input: &OcrInput, words: &[RotatedRect] ) -> Vec<Vec<RotatedRect>>

Perform layout analysis to group words into lines and sort them in reading order.

words is an unordered list of text word rectangles found by OcrEngine::detect_words. The result is a list of lines, in reading order. Each line is a sequence of word bounding rectangles, in reading order.

source

pub fn recognize_text( &self, input: &OcrInput, lines: &[Vec<RotatedRect>] ) -> Result<Vec<Option<TextLine>>, Box<dyn Error>>

Recognize lines of text in an image.

lines is an ordered list of the text line boxes in an image, produced by OcrEngine::find_text_lines.

The output is a list of TextLines corresponding to the input image regions. Entries can be None if no text was found in a given line.

source

pub fn get_text(&self, input: &OcrInput) -> Result<String, Box<dyn Error>>

Convenience API that extracts all text from an image as a single string.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.