use oneocr_rs::{OcrEngine, OcrOptions, OneOcrError};
use std::path::Path;
fn main() -> Result<(), OneOcrError> {
let input_image_path = std::env::args()
.nth(1)
.unwrap_or("./assets/sample.jpg".to_string());
let image_path = Path::new(&input_image_path);
let ocr_options = OcrOptions {
include_word_level_details: true,
..Default::default()
};
let ocr_engine = OcrEngine::new_with_options(ocr_options)?;
ocr_engine.set_max_recognition_line_count(1000)?;
let ocr_result = ocr_engine.run(image_path.into())?;
println!("Image angle: {:.2}", ocr_result.image_angle);
for line in &ocr_result.lines {
println!();
println!("Line: {}", line.text);
println!("{}", line.bounding_box);
let (handwritten, confidence) = line.get_line_style()?;
println!(
"Line style: handwritten: {handwritten}, handwritten style confidence: {confidence}"
);
if let Some(words) = &line.words {
for word in words {
print!("Word: [{}, {:.2}]\t", word.text, word.confidence);
println!("{}", word.bounding_box);
}
}
}
Ok(())
}