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
impl OcrEngine
sourcepub fn new(params: OcrEngineParams) -> Result<OcrEngine, Box<dyn Error>>
pub fn new(params: OcrEngineParams) -> Result<OcrEngine, Box<dyn Error>>
Construct a new engine from a given configuration.
sourcepub fn prepare_input(
&self,
image: NdTensorView<'_, f32, 3>
) -> Result<OcrInput, Box<dyn Error>>
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.
sourcepub fn detect_words(
&self,
input: &OcrInput
) -> Result<Vec<RotatedRect>, Box<dyn Error>>
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.
sourcepub fn find_text_lines(
&self,
_input: &OcrInput,
words: &[RotatedRect]
) -> Vec<Vec<RotatedRect>>
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.
sourcepub fn recognize_text(
&self,
input: &OcrInput,
lines: &[Vec<RotatedRect>]
) -> Result<Vec<Option<TextLine>>, Box<dyn Error>>
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.