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>
pub fn new(params: OcrEngineParams) -> Result<OcrEngine>
Construct a new engine from a given configuration.
Sourcepub fn prepare_input(&self, image: ImageSource<'_>) -> Result<OcrInput>
pub fn prepare_input(&self, image: ImageSource<'_>) -> Result<OcrInput>
Preprocess an image for use with other methods of the engine.
Sourcepub fn detect_words(&self, input: &OcrInput) -> Result<Vec<RotatedRect>>
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.
Sourcepub fn detect_text_pixels(&self, input: &OcrInput) -> Result<NdTensor<f32, 2>>
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.
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>>>
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.
Sourcepub fn prepare_recognition_input(
&self,
input: &OcrInput,
line: &[RotatedRect],
) -> Result<NdTensor<f32, 2>>
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].
Sourcepub fn detection_threshold(&self) -> f32
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.
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 more