Skip to main content

Crate tesseract_ocr_static

Crate tesseract_ocr_static 

Source
Expand description

This crate provides ergonomic Rust interface for underlying Tesseract OCR library. There are two main structs: TextRecognizer and LayoutAnalyzer. TextRecognizer allows one to recognize text from the picture and outputs the text, the bounding boxes and other parameters. LayoutAnalyzer allows one to analyze the layout without recognizing text; it should consume less memory than TextRecognizer.

Pictures can be loaded into the library via Image struct that accepts images in raw RGB/RGBA formats; no other formats are supported. If you need to read an image from a file in another format, you can do so with any Rust crate (e.g. image).

§Examples

§Simple character recognition

use tesseract_ocr_static::{Image, TextRecognizer};
use image::ImageReader;

let rgb = ImageReader::open("hello.txt").unwrap().decode().unwrap().into_rgb8();
let image = Image::from_rgb(rgb.width(), rgb.height(), rgb.as_raw()).unwrap();
let mut recognizer = TextRecognizer::new().unwrap();
let results = recognizer.recognize_text(&image).unwrap();
assert_eq!("Hello world", results.get_utf8_text().as_str());
use tesseract_ocr_static::{Image, LayoutLevel, TextRecognizer};
use image::ImageReader;

let rgb = ImageReader::open("hello.txt").unwrap().decode().unwrap().into_rgb8();
let image = Image::from_rgb(rgb.width(), rgb.height(), rgb.as_raw()).unwrap();
let mut recognizer = TextRecognizer::new().unwrap();
let results = recognizer.recognize_text(&image).unwrap();
let mut iter = results.iter();
while let Some(word) = iter.next(LayoutLevel::Word) {
    println!(
        "Word {:?}, confidence {:.1}, bounding box {:?}",
        word.get_utf8_text(LayoutLevel::Word).as_str(),
        word.confidence(LayoutLevel::Word),
        word.bounding_box(LayoutLevel::Word),
    );
}

§Build customization

Please consult tesseract-ocr-static-c crate’s documentation.

Structs§

ChoiceIterator
An iterator over classifier choices for a symbol.
ClassifierChoice
A symbol choice.
Config
OCR configuration.
Element
Text layout element.
FontAttrs
Font attributes.
Image
Tesseract-specific image.
InitFailed
Initialization failed
InvalidImage
Invalid image
InvalidVariable
Invalid variable
LayoutAnalyzer
Layout analysis engine.
LayoutIter
An iterator over text layout elements.
Line
Line.
Monitor
Monitor tracks text recognition progress and can be used to set the timeout.
OrientationParams
Orientation.
ParagraphInfo
Paragraph information.
RecognitionFailed
Recognition failed
RecognitionResults
Text recognition results.
Rectangle
Rectangle.
ResultIter
An iterator over recognition results.
Tesseract
Common tesseract methods.
Text
Tesseract-specific string.
TextElement
Text element.
TextRecognizer
OCR engine interface.
Utf8Text
Tesseract-specific UTF-8 string.
WriteFailed
Write failed

Enums§

BlockType
Block type.
LayoutLevel
Element of layout hierarchy
OcrEngineMode
OCR engine mode
Orientation
Text position on the page.
PageSegmentationMode
Page layout analysis modes.
ParagraphJustification
Paragraph alignment.
TextlineOrder
The order of the lines of text.
WritingDirection
Text writing direction.

Functions§

leptonica_version
Returns Leptonica library version.
version
Returns Tesseract library version.