bin+lib rusty-tesseract

A Rust wrapper for Google Tesseract

8 stable releases

1.1.7 Jul 26, 2023
1.1.6 Jul 17, 2023
1.1.5 Jun 20, 2023
1.1.4 Mar 30, 2023
1.0.0 Feb 24, 2022

#35 in Configuration

Download history 12/week @ 2023-06-07 118/week @ 2023-06-14 56/week @ 2023-06-21 31/week @ 2023-06-28 39/week @ 2023-07-05 71/week @ 2023-07-12 75/week @ 2023-07-19 71/week @ 2023-07-26 44/week @ 2023-08-02 128/week @ 2023-08-09 82/week @ 2023-08-16 59/week @ 2023-08-23 36/week @ 2023-08-30 166/week @ 2023-09-06 59/week @ 2023-09-13 78/week @ 2023-09-20

346 downloads per month

MIT license

735 lines


A Rust wrapper for Google Tesseract

GitHub last commit GitHub Stars Forks Github All Releases Issues


Add the following line to your Cargo.toml file:

rusty-tesseract = "1.1.7"


  • 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.


Tesseract: https://github.com/tesseract-ocr/tesseract


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 _ = Image::from_path("img/string.png");

// or instantiate Image from a DynamicImage
let dynamic_image = ImageReader::open("img/string.png")
let img = Image::from_dynamic_image(&dynamic_image).unwrap();

2. Set tesseract parameters

Set tesseract parameters using the Args struct.

let default_args = 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 {
    //model language (tesseract default = 'eng')
    //available languages can be found by running 'rusty_tesseract::get_tesseract_langs()'
    lang: "eng",

    //map of config variables
    //this example shows a whitelist for the normal alphabet. Multiple arguments are allowed.
    //available arguments can be found by running 'rusty_tesseract::get_tesseract_config_parameters()'
    config_variables: HashMap::from([(
    dpi: Some(150),       // specify DPI for input image
    psm: Some(6),         // define page segmentation mode 6 (i.e. "Assume a single uniform block of text")
    oem: Some(3),         // define optical character recognition mode 3 (i.e. "Default, based on what is available")

3. Get the tesseract model output

Choose either string, bounding box or data output:

// define parameters
let mut my_args = Args {
    lang: "eng",
    config_variables: HashMap::from([(
    dpi: Some(150),
    psm: Some(6),
    oem: Some(3)

// string output
let output = rusty_tesseract::image_to_string(&img, &my_args).unwrap();
    println!("The String output is: {:?}", output);

// image_to_boxes creates a BoxOutput containing the parsed output from Tesseract when using the "makebox" Parameter
let box_output = rusty_tesseract::image_to_boxes(&img, &my_args).unwrap();
    "The first boxfile symbol is: {}",
println!("The full boxfile output is:\n{}", box_output.output);

// image_to_data creates a DataOutput containing the parsed output from Tesseract when using the "TSV" Parameter
let data_output = rusty_tesseract::image_to_data(&img, &my_args).unwrap();
let first_text_line = &data_output.data[4];
    "The first text is '{}' with confidence {}",
    first_text_line.text, first_text_line.conf
println!("The full data output is:\n{}", data_output.output);

Get information about tesseract

//tesseract version
let tesseract_version = rusty_tesseract::get_tesseract_version().unwrap();
println!("The tesseract version is: {:?}", tesseract_version);

//available languages
let tesseract_langs = rusty_tesseract::get_tesseract_langs().unwrap();
println!("The available languages are: {:?}", tesseract_langs);

//available config parameters
let parameters = rusty_tesseract::get_tesseract_config_parameters().unwrap();
println!("Example config parameter: {}", parameters.config_parameters.first().unwrap());


  1. Fork the repository
  2. Create a new feature branch (git checkout -b my-feature-branch-name)
  3. Commit your new changes (git commit -m 'commit message' <changed-file>)
  4. Push changes to the branch (git push origin my-feature-branch-name)
  5. Create a Pull Request


~181K SLoC