rusty-tesseract
A Rust wrapper for Google Tesseract
Installation
Add the following line to your Cargo.toml file:
rusty-tesseract = "1.1.10"
Description
- Brings all relevant command-line tesseract functionality to Rust
- Partly based on the Python wrapper for tesseract (i.e. https://github.com/madmaze/pytesseract)
- Enables testing a pre-trained tesseract model and outputting the results in different formats such as strings, bounding boxes, dicts, or dataframes.
Dependencies
Tesseract: https://github.com/tesseract-ocr/tesseract
Usage
1. Read Image
Create an Image object by specifying a path or alternatively a DynamicImage from the image crate https://docs.rs/image/latest/image/
// you can use the from_path function
let _ = from_path;
// or instantiate Image from a DynamicImage
let dynamic_image = open
.unwrap
.decode
.unwrap;
let img = from_dynamic_image.unwrap;
2. Set tesseract parameters
Set tesseract parameters using the Args struct.
let default_args = default;
// the default parameters are
/*
Args {
lang: "eng",
dpi: Some(150),
psm: Some(3),
oem: Some(3),
}
*/
// fill your own argument struct if needed
// Optional arguments are ignored if set to `None`
let mut my_args = Args ;
3. Get the tesseract model output
Choose either string, bounding box or data output:
// define parameters
let mut my_args = Args ;
// string output
let output = image_to_string.unwrap;
println!;
// image_to_boxes creates a BoxOutput containing the parsed output from Tesseract when using the "makebox" Parameter
let box_output = image_to_boxes.unwrap;
println!;
println!;
// image_to_data creates a DataOutput containing the parsed output from Tesseract when using the "TSV" Parameter
let data_output = image_to_data.unwrap;
let first_text_line = &data_output.data;
println!;
println!;
Get information about tesseract
//tesseract version
let tesseract_version = get_tesseract_version.unwrap;
println!;
//available languages
let tesseract_langs = get_tesseract_langs.unwrap;
println!;
//available config parameters
let parameters = get_tesseract_config_parameters.unwrap;
println!;
Contributing
- Fork the repository
- Create a new feature branch (
git checkout -b my-feature-branch-name
) - Commit your new changes (
git commit -m 'commit message' <changed-file>
) - Push changes to the branch (
git push origin my-feature-branch-name
) - Create a Pull Request