mod rusty_tesseract;
use rusty_tesseract::{Image, Args};
use ndarray::Array3;
use std::collections::HashMap;
mod error;
fn main() {
let mut img = Image::new(
String::from("img/string.png"),
Array3::<u8>::zeros((100, 100, 3))
);
let mut 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_STRING);
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.Output_DATAFRAME);
let data = rusty_tesseract::image_to_data(&img, default_args);
println!("\nThe data output is: {:?}", data.Output_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 mut 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_STRING, "D\nO\nL\nO\nR\nS\nI\n\nT\n\u{c}");
}
#[test]
fn horizontal_text() {
let mut 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_STRING, "Lorem ipsum dolor sit amet\n\u{c}");
}
#[test]
fn image_to_data() {
let mut 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_STRING, "LOREM IPSUM DOLOR SIT AMET\n\u{c}");
}
#[test]
fn image_to_string() {
let mut 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_STRING, "LOREM IPSUM DOLOR SIT AMET\n\u{c}");
}
#[test]
fn image_to_boxes() {
let mut 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_STRING, "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 185 59 0\nP 191 26 214 59 0\nS 216 25 237 60 0\nU 240 25 263 59 0\nM 269 26 304 59 0\nD 323 26 352 59 0\nO 355 25 390 60 0\nL 360 25 415 60 0\nO 395 26 413 59 0\nR 413 25 476 60 0\nS 490 25 509 60 0\nI 490 25 518 60 0\nT 521 26 540 59 0\nA 553 26 586 59 0\nM 589 26 624 59 0\nE 603 26 649 59 0\nT 630 26 671 59 0\n");
}
}