Skip to main content

OcrEngine

Struct 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>

Construct a new engine from a given configuration.

Source

pub fn prepare_input(&self, image: ImageSource<'_>) -> Result<OcrInput>

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

Source

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

Detect text words in an image.

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

Source

pub fn detect_text_pixels(&self, input: &OcrInput) -> Result<NdTensor<f32, 2>>

Detect text pixels in an image.

Returns an (H, W) tensor indicating the probability of each pixel in the input being part of a text word. This is a low-level API that is useful for debugging purposes. Use detect_words for a higher-level API that returns oriented bounding boxes of words.

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>>>

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 prepare_recognition_input( &self, input: &OcrInput, line: &[RotatedRect], ) -> Result<NdTensor<f32, 2>>

Prepare an image for input into the text line recognition model.

This method exists to help with debugging recognition issues by exposing the preprocessing that OcrEngine::recognize_text does before it feeds an image into the recognition model. Use OcrEngine::recognize_text to recognize text.

line is a sequence of RotatedRects that make up a line of text.

Returns a greyscale (H, W) image with values in [-0.5, 0.5].

Source

pub fn detection_threshold(&self) -> f32

Return the confidence threshold applied to the output of the text detection model to determine whether a pixel is text or not.

Source

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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>,

Source§

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>,

Source§

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.