use rusty_tesseract::{ndarray::Array3, Args, Image};
use std::collections::HashMap;
mod error;
fn main() {
let _ = Image::new(
String::from("img/string.png"),
Array3::<u8>::zeros((100, 100, 3)),
);
let img = Image {
path: String::from("img/string.png"),
ndarray: Array3::<u8>::zeros((100, 100, 3)), };
let default_args = Args::new();
let tesseract_version = rusty_tesseract::get_tesseract_version();
println!("The tesseract version is: {:?}", tesseract_version);
let mut image_to_string_args = Args {
out_filename: "out",
lang: "eng",
config: HashMap::new(),
dpi: 150,
boxfile: false,
};
image_to_string_args.config.insert("psm", "6");
image_to_string_args.config.insert("oem", "3");
let output = rusty_tesseract::image_to_string(&img, image_to_string_args);
println!("\nThe String output is: {:?}", output.output);
let mut image_to_boxes_args = Args {
out_filename: "font_name.font.exp0",
lang: "eng",
config: HashMap::new(),
dpi: 150,
boxfile: true,
};
image_to_boxes_args.config.insert("psm", "6");
image_to_boxes_args.config.insert("oem", "3");
let boxes = rusty_tesseract::image_to_boxes(&img, image_to_boxes_args);
println!("\nThe Boxfile output is: {:?}", boxes.dataframe);
let data = rusty_tesseract::image_to_data(&img, default_args);
println!("\nThe data output is: {:?}", data.dict);
println!("\nThe confidence tesstable can be found in the [out_filename].tsv file!\n");
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vertical_text() {
let img = Image::new(
String::from("img/vertical_text.png"),
Array3::<u8>::zeros((0, 0, 3)),
);
let mut image_to_string_args = Args {
out_filename: "out",
lang: "eng",
config: HashMap::new(),
dpi: 150,
boxfile: false,
};
image_to_string_args.config.insert("psm", "6");
image_to_string_args.config.insert("oem", "3");
let output_test = rusty_tesseract::image_to_string(&img, image_to_string_args);
assert_eq!(output_test.output, "D\nO\nL\nO\nR\nS\nI\n\nT\n");
}
#[test]
fn horizontal_text() {
let img = Image::new(
String::from("img/horizontal_text.png"),
Array3::<u8>::zeros((0, 0, 3)),
);
let default_args = Args::new();
let output_test = rusty_tesseract::image_to_string(&img, default_args);
assert_eq!(output_test.output.trim(), "Lorem ipsum dolor sit amet");
}
#[test]
fn image_to_data() {
let img = Image::new(
String::from("img/string.png"),
Array3::<u8>::zeros((0, 0, 3)),
);
let default_args = Args::new();
let output_test = rusty_tesseract::image_to_data(&img, default_args);
assert_eq!(output_test.output.trim(), "LOREM IPSUM DOLOR SIT AMET");
}
#[test]
fn image_to_string() {
let img = Image::new(
String::from("img/string.png"),
Array3::<u8>::zeros((0, 0, 3)),
);
let default_args = Args::new();
let output_test = rusty_tesseract::image_to_string(&img, default_args);
assert_eq!(output_test.output.trim(), "LOREM IPSUM DOLOR SIT AMET");
}
#[test]
fn image_to_boxes() {
let img = Image::new(
String::from("img/string.png"),
Array3::<u8>::zeros((0, 0, 3)),
);
let mut image_to_boxes_args = Args {
out_filename: "eng.testcase.exp0",
lang: "eng",
config: HashMap::new(),
dpi: 150,
boxfile: true,
};
image_to_boxes_args.config.insert("psm", "6");
image_to_boxes_args.config.insert("oem", "3");
let boxes_test = rusty_tesseract::image_to_boxes(&img, image_to_boxes_args);
assert_eq!(boxes_test.output.trim(), "L 18 26 36 59 0\nO 35 25 70 60 0\nR 75 26 98 59 0\nE 103 26 122 59 0\nM 127 26 162 59 0\nI 181 26 214 59 0\nP 203 25 226 60 0\nS 216 25 263 60 0\nU 252 25 280 60 0\nM 269 26 304 59 0\nD 323 26 352 59 0\nO 355 25 390 60 0\nL 395 26 413 59 0\nO 413 25 448 60 0\nR 453 26 476 59 0\nS 490 25 511 60 0\nI 514 26 518 59 0\nT 521 26 540 59 0\nA 553 26 586 59 0\nM 589 26 624 59 0\nE 630 26 649 59 0\nT 652 26 671 59 0");
}
}