ocr 0.1.0

A minimalist OCR library for Rust — from scratch, no external engine
Documentation
use std::path::PathBuf;

use anyhow::Result;
use clap::Parser;
use ocr::OcrEngine;

#[derive(Parser)]
#[command(name = "ocr-rs", version, about = "A minimalist OCR tool — built from scratch")]
struct Cli {
    /// Path to the image file
    image_path: PathBuf,

    /// Output format: text, json
    #[arg(short, long, default_value = "text")]
    format: String,

    /// Enable image preprocessing
    #[arg(long)]
    preprocess: bool,
}

fn main() -> Result<()> {
    let cli = Cli::parse();

    let engine = OcrEngine::new().preprocessing(cli.preprocess);

    let result = engine.recognize_file(&cli.image_path)?;

    match cli.format.as_str() {
        "json" => println!("{}", serde_json::to_string_pretty(&result)?),
        _ => println!("{}", result.text),
    }

    Ok(())
}