swordfish/swordfish-common/src/tesseract.rs

16 lines
545 B
Rust
Raw Normal View History

2023-12-31 15:55:32 +00:00
pub use leptess::{LepTess, Variable};
2024-01-01 13:15:51 +00:00
pub fn init_tesseract(numeric_only: bool) -> Result<LepTess, String> {
2023-12-31 15:55:32 +00:00
let mut lep_tess = match LepTess::new(None, "eng") {
Ok(lep_tess) => lep_tess,
Err(why) => return Err(format!("Failed to initialize Tesseract: {:?}", why)),
};
2024-01-01 13:15:51 +00:00
if numeric_only {
match lep_tess.set_variable(Variable::TesseditCharWhitelist, "0123456789") {
Ok(_) => (),
Err(why) => return Err(format!("Failed to set whitelist: {:?}", why)),
};
}
2023-12-31 15:55:32 +00:00
Ok(lep_tess)
}