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());§Print recognized text and corresponding bounding boxes
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§
- Choice
Iterator - An iterator over classifier choices for a symbol.
- Classifier
Choice - A symbol choice.
- Config
- OCR configuration.
- Element
- Text layout element.
- Font
Attrs - Font attributes.
- Image
- Tesseract-specific image.
- Init
Failed - Initialization failed
- Invalid
Image - Invalid image
- Invalid
Variable - Invalid variable
- Layout
Analyzer - Layout analysis engine.
- Layout
Iter - An iterator over text layout elements.
- Line
- Line.
- Monitor
- Monitor tracks text recognition progress and can be used to set the timeout.
- Orientation
Params - Orientation.
- Paragraph
Info - Paragraph information.
- Recognition
Failed - Recognition failed
- Recognition
Results - Text recognition results.
- Rectangle
- Rectangle.
- Result
Iter - An iterator over recognition results.
- Tesseract
- Common tesseract methods.
- Text
- Tesseract-specific string.
- Text
Element - Text element.
- Text
Recognizer - OCR engine interface.
- Utf8
Text - Tesseract-specific UTF-8 string.
- Write
Failed - Write failed
Enums§
- Block
Type - Block type.
- Layout
Level - Element of layout hierarchy
- OcrEngine
Mode - OCR engine mode
- Orientation
- Text position on the page.
- Page
Segmentation Mode - Page layout analysis modes.
- Paragraph
Justification - Paragraph alignment.
- Textline
Order - The order of the lines of text.
- Writing
Direction - Text writing direction.
Functions§
- leptonica_
version - Returns Leptonica library version.
- version
- Returns Tesseract library version.